我正在尝试将模块拆分为多个文件。我关注了这个问题,但没有运气,我似乎无法访问同一模块中但不同文件中的类。
我正在为 Visual Studio 2012 使用 TypeScript 0.8.2 插件
/* filesystem */
- /core
- - Router.ts
- - Server.ts
- /DefinitelyTyped
- - ..
- index.ts
/* file Router.ts */
///<reference path='../DefinitelyTyped/node/node.d.ts'/>
import Url = module("url");
module Core {
export class Router {
static route(url: string) {
var pathname: string = Url.parse(url).pathname;
var query: string = Url.parse(url).query;
console.log("About to route to " + pathname);
}
}
}
/* file Server.ts */
///<reference path='../DefinitelyTyped/node/node.d.ts'/>
///<reference path="Router.ts"/>
import Http = module("http");
module Core {
export class Server {
private server: Http.Server;
private port: number;
constructor(port: number) {
this.port = port;
this.server = Http.createServer(this.onRequest);
this.server.listen(this.port);
console.log("Server started at http://127.0.0.1:" + this.port + "/.");
}
private onRequest(request: Http.ServerRequest, response: Http.ServerResponse) {
var url: string = request.url;
console.log("Received request: \"" + request.url + "\".");
Router.route(url); //problem: Name 'Router' doesn't exist in this scope...
response.writeHead(200, { "Content-Type": "text/plain" });
response.write(url);
response.end();
}
public getPort(): number {
return this.port;
}
}
}
那么,我错过了什么?