Home Ask Login Register

Developers Planet

Your answer is one click away!

Sud February 2016

Including Typescript code in Relay (System.js import)

How to include system.js to fix the error below? Or is there any other solution?

I downloaded the relay-starter-kit (https://github.com/relayjs/relay-starter-kit), changed the database.js to database.ts with the below content (Snippet 1).

I ran "npm run update-schema" and got the error

System.register([], function (exports_1) {
^

ReferenceError: System is not defined
    at Object.<anonymous> (database.js:9:1)
    at Module._compile (module.js:410:26)
..

I know it occurs because update-schema uses scripts/updateSchema.js -> data/schema.js -> which imports objects from data/database.js (compiled version of database.ts) has -

System.register([], function(exports_1) {

Snippet 1:

/// <reference path="./interface.d.ts" />

export class User implements IUser{
    constructor (public id: String, public name: String){
        this.id = id;
        this.name = name;
    }
}
// Model types
class UserModel extends User implements IUserModel {

     constructor(public id: String, public name: String){
         super (id,name);
     }
     getUser ():IUser{
         return this;
     }
     setUser (_User:IUser) : void {
         this.id = _User.id;
         this.name = _User.name;
     }  
    getUserbyId (_id:String):IUser{
        if (_id === this.id){
            return this;
        } else {
            return null;
        }    
    }  

}

export class Widget implements IWidget{
    constructor (public id: String, public name: String){
        this.id = id;
        this.name = name;
    }
}
// Model types
class WidgetModel extends Widget implements IWidgetModel {

     constructor(public id: String, public name: String){
         super (id,name);
     }
     getWidget ():IWidget{
         return this;
     }
     setWidget (_Widget:IWidget) : void {
         this.id = _Widget.id;
            

Answers


Sud February 2016

tsconfig.json had

"module": "system",

Changed it to

"module": "umd",

and it worked.

Post Status

Asked in February 2016
Viewed 2,017 times
Voted 10
Answered 1 times

Search




Leave an answer


Quote of the day: live life