Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用Typescript表达4.x_Node.js_Express_Typescript - Fatal编程技术网

Node.js 使用Typescript表达4.x

Node.js 使用Typescript表达4.x,node.js,express,typescript,Node.js,Express,Typescript,我正在尝试用typescript制作一个express应用程序 这是我目前的代码: //<reference path="./server/types/node.d.ts"/> //<reference path="./server/types/express.d.ts"/> import express = require('express'); var app = express(); app.get('/', function(req, res) {

我正在尝试用typescript制作一个express应用程序

这是我目前的代码:

//<reference path="./server/types/node.d.ts"/>
//<reference path="./server/types/express.d.ts"/>

import express = require('express');

var app = express();

app.get('/', function(req, res) {
    res.send('hi');
});

app.listen(3000);

你引用的评论是错误的。需要有三个斜杠
//

///<reference path="./server/types/node.d.ts"/>
///<reference path="./server/types/express.d.ts"/>
///
///

如果您正在使用此引用文件,则获得该错误的唯一方法是您的引用注释错误,并且typescript没有读取到
express.d.ts
:)

由于您使用的是express 4.x,并且类型定义不是最新的,我是否可以添加这一点,您将丢失Express4.x的一些关键功能,例如路由器

此时有两种选择:更新类型定义或使用

var express = require('express');

相反,它消除了typescript提供的一些好处,但将来在使用其他节点模块(如mongoose)时肯定会遇到这种情况。

我现在更改了这一点,但仍然得到了一些好处“errorTS5037:除非提供了“-module”标志,否则无法编译外部模块。好的,我已经得到了它。我只是按照你在那篇帖子上的指示做的:
var express = require('express');