我需要在TypeScript和Node中编写服务器。
结果是:
/// <reference path="definitions/commonjs.d.ts" />
/// <reference path="definitions/node.d.ts" />
var http = require("http");
namespace MyProj {
export class Server {
public run() {
var server = http.createServer(); // TypeScript does not recognize 'http'
}
}
}
但我无法理解如何引用http
模块。我在哪里可以找到类型?在定义文件中,我很难识别这些信息。
答案 0 :(得分:17)
这是因为您正在使用require
。使用import
而不是它会识别并且还会给你很好的智能感知: - )
import * as http from "http"