javascript - Including Typescript code in Relay (System.js import) -


how include system.js fix error below? or there other solution?

i downloaded relay-starter-kit (https://github.com/relayjs/relay-starter-kit), changed database.js database.ts below content (snippet 1).

i ran "npm run update-schema" , got error

system.register([], function (exports_1) { ^  referenceerror: system not defined     @ object.<anonymous> (database.js:9:1)     @ module._compile (module.js:410:26) .. 

i know occurs because update-schema uses scripts/updateschema.js -> data/schema.js -> imports objects 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;          this.name = _widget.name;      }     getwidgetbyid (_id:string):iwidget{         if (_id === this.id){             return this;         } else {             return null;         }         }        }  // mock data var viewer:iusermodel = new usermodel('1','anonymous');  var widgets:iwidget[] = ['what\'s-it', 'who\'s-it', 'how\'s-it'].map((name:string, i:any) => {   let widget:iwidgetmodel = new widgetmodel(name,`${i}`);   return widget; });   export function getuser (_id:string):iuser {           return viewer.getuserbyid(_id);   }    export function getviewer ():iuser {       return viewer.getuser();   }   export function getwidget (_id:string):any {       widgets.foreach(           w => {               if (w.id === _id)                    return w;               else                    return null;           }       );   }   export function getwidgets (): iwidget[]{       return widgets;   } 

tsconfig.json had

"module": "system",

changed

"module": "umd",

and worked.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -