在 Relay 中包含 Typescript 代码(System.js 导入)

Including Typescript code in Relay (System.js import)

如何包含 system.js 以修复以下错误?或者还有其他解决办法吗?

我下载了中继入门套件 (https://github.com/relayjs/relay-starter-kit),将 database.js 更改为 database.ts,内容如下(片段 1)。

我 运行 "npm run update-schema" 得到了错误

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

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

我知道它发生是因为 update-schema 使用 scripts/updateSchema.js -> data/schema.js -> 从 data/database.js 导入对象([=31 的编译版本=]) 有 -

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

片段 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 有

"module": "system",

改为

"module": "umd",

成功了。