I need to write a server in TypeScript and 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. 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
. use import
instead it will recognize and also will give you nice intellisense :-)
import * as http from "http"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.