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

Javascript 在中继中包含Typescript代码(System.js导入),javascript,typescript,systemjs,relay,Javascript,Typescript,Systemjs,Relay,如何包含system.js来修复以下错误?或者还有其他解决办法吗 我下载了中继启动器工具包(),将database.js更改为database.ts,内容如下(代码片段1) 我运行了“npm运行更新模式”并得到了错误 System.register([], function (exports_1) { ^ ReferenceError: System is not defined at Object.<anonymous> (database.js:9:1) at

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

我下载了中继启动器工具包(),将database.js更改为database.ts,内容如下(代码片段1)

我运行了“npm运行更新模式”并得到了错误

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

ReferenceError: System is not defined
    at Object.<anonymous> (database.js:9:1)
    at Module._compile (module.js:410:26)
..
片段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;
  }
//
导出类用户实现IUser{
构造函数(公共id:String,公共名称:String){
this.id=id;
this.name=名称;
}
}
//模型类型
类UserModel扩展了用户实现的IUserModel{
构造函数(公共id:String,公共名称:String){
super(id,name);
}
getUser():IUser{
归还这个;
}
setUser(_User:IUser):无效{
this.id=\u User.id;
this.name=\u User.name;
}  
getUserbyId(_id:String):IUser{
if(_id==this.id){
归还这个;
}否则{
返回null;
}    
}  
}
导出类小部件实现IWidget{
构造函数(公共id:String,公共名称:String){
this.id=id;
this.name=名称;
}
}
//模型类型
类WidgetModel扩展小部件实现IWidgetModel{
构造函数(公共id:String,公共名称:String){
super(id,name);
}
getWidget():IWidget{
归还这个;
}
setWidget(_Widget:IWidget):void{
this.id=_Widget.id;
this.name=_Widget.name;
}
getWidgetbyId(_id:String):IWidget{
if(_id==this.id){
归还这个;
}否则{
返回null;
}    
}       
}
//模拟数据
变量查看器:IUserModel=newusermodel('1','Anonymous');
var小部件:IWidget[]=['What's-it'、'Who's-it'、'How's-it'].map((名称:String,i:any)=>{
let小部件:IWidgetModel=newwidgetmodel(名称,`${i}`);
返回控件;
});
导出函数getUser(_id:String):IUser{
返回viewer.getUserbyId(_id);
} 
导出函数getViewer():IUser{
返回viewer.getUser();
}
导出函数getWidget(_id:String):任意{
弗雷奇酒店(
w=>{
如果(w.id===\u id)
返回w;
其他的
返回null;
}
);
}
导出函数getWidgets():IWidget[]{
返回窗口小部件;
}
tsconfig.json

“模块”:“系统”

改成

“模块”:“umd”

它成功了。

tsconfig.json

“模块”:“系统”

改成

“模块”:“umd”

它成功了

/// <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;
  }