[英]How to use Node `http` module in TypeScript
I need to write a server in TypeScript and Node. 我需要在TypeScript和Node中编写服务器。
The result is: 结果是:
/// <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'
}
}
}
But I cannot understand how I can reference the http
module. 但我无法理解我如何引用
http
模块。 Where can I find the types? 我在哪里可以找到类型? In the definition file i am having hard time recognizing this information.
在定义文件中,我很难识别这些信息。
It's because of you are using require
. 这是因为你正在使用
require
。 use import
instead it will recognize and also will give you nice intellisense :-) 使用
import
而不是它会识别并且还会给你很好的intellisense :-)
import * as http from "http"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.