答案 0 :(得分:1)
请参见https://stackoverflow.com/a/35074833/1937643。
您要的是:
var http = require("http");
declare module NodeJS {
interface Global {
spotConfig: string
}
}
//create a server object:
http
.createServer(function (req, res) {
// assign a new value to the global property
global.spotConfig = "anything";
console.log(global.spotConfig);
// error TS2339: Property 'config' does not exist on type 'Global'.
res.write("Hello World!"); //write a response to the client
res.end(); //end the response
})
.listen(8080); //the server object listens on port 8080