typescript - 如何在打字中安装 express ?

标签 typescript definitelytyped tsd

我正在尝试在我的应用中使用 expressjs。

使用 typings install express --ambient --save 安装后,我运行 tsc,但出现两个错误:

typings/main/ambient/express/index.d.ts(17,34): error TS2307: Cannot find module 'serve-static'. typings/main/ambient/express/index.d.ts(18,27): error TS2307: Cannot find module 'express-serve-static-core'.

所以,我尝试同时安装:

typings install serve-static --ambient --save
typings install express-serve-static --ambient --save

然后我再次运行 tsc,但又出现一个错误:

typings/main/ambient/serve-static/index.d.ts(79,24): error TS2307: Cannot find module 'mime'.

如何解决这些问题?如何自动安装 express 的所有依赖项?

最佳答案

使用 Typescript 2.0( https://blogs.msdn.microsoft.com/typescript/2016/09/22/announcing-typescript-2-0/ ),现在不同了:

如果您使用以下命令安装 typescript:

npm install -g typescript@2.0

你必须使用命令安装 express typings

npm install --save @types/express

而不是像早期版本那样使用环境/全局安装类型。 typings 安装在 node_modules/@types/express 目录

在执行 typesnpm install 之后,您的 package.json 将包含以下片段:

"dependencies": {
    "@types/express": "^4.0.33"
  }

关于typescript - 如何在打字中安装 express ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36037977/

相关文章:

javascript - 如何从 yarn.lock 知道当前安装包的版本

node.js - Typescript Nodejs Dockerfile : error TS5057: Cannot find a tsconfig. 指定目录下的json文件: '.'

javascript - TypeScript 构建错误 : Property does not exist on type 'IStateParamsService'

javascript - Typescript ts-check javascript 泛型

Travis 构建中的 typescript 失败

javascript - 在搜索类型定义时何时使用环境?

ssl - TSD 错误 : self signed certificate in certificate chain

javascript - 如何解决此 TypeScript 错误 : "Expected 0-1 arguments, but got 2"

javascript - Typescript 中的对象类型

typescript - 什么是 "DefinitelyTyped"?