我尝试使用typescript设置一个restify项目.经过各种尝试后,我可以使用tsconfig.json中的"module:commonjs"创建一个工作版本
我更喜欢使用系统 - 但我无法使用systemjs进行设置
boot.ts
import {AppServer} from './app';
var _appServer = new AppServer();
Run Code Online (Sandbox Code Playgroud)
tsconfig.json
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules"
]
}
Run Code Online (Sandbox Code Playgroud)
app.ts
/// <reference path="typings/restify/restify.d.ts" />
import {Server, Response, Request, createServer} from 'restify';
export class AppServer {
private server: Server;
constructor() {
this.init();
}
init() {
this.server = createServer();
this.server.get('/hello/:name', this.respond);
this.server.listen(8080, () => {
console.log('%s listening at %s', this.server.name, this.server.url); …Run Code Online (Sandbox Code Playgroud)