【问题标题】:How to reference @types/module in typescript?如何在打字稿中引用@types/module?
【发布时间】:2016-09-22 13:35:38
【问题描述】:

通过npm 安装@types/express 之类的模块后,如何在打字稿中引用它?

我尝试了以下方法:

  1. /// <reference path="../node_modules/@types/express/index.d.ts" /> 还是给我can not find module 'express' 错误

  2. import * as express from '@types/express'; 可以通过 typescript 编译,但是编译后会是require('@types/express'),应该是require('express')

【问题讨论】:

  • 为什么不import * as express from 'express'
  • 我也试过了,给我can not find module 'express',我想是因为express模块​​在package.json中不包含typings字段。
  • 您使用的是什么版本的 tsc?这应该是 2.0 的一个特性。
  • 我用的是1.8.10,可能是这个原因,等我试试,谢谢!
  • 不幸的是我发现最新版本是 1.8 :(

标签: node.js express typescript


【解决方案1】:

这是 TypeScript 2.0+ 的版本。它不适用于早于该版本的版本。

截至目前,2.0 仍处于测试阶段,但有一个候选版本可用作 typescript@rc 版本。要安装我运行:

npm install -g typescript@rc

夜间构建也可作为 typescript@next

npm install -g typescript@next

【讨论】:

  • 现在有一个包含大量错误修复的候选版本:npm install -g typescript@rc
  • 我认为还有一个更新的@beta,来自他们的博客blogs.msdn.microsoft.com/typescript/2016/07/11/…
  • 根据npm info typescript,可用的标签和版本是:'dist-tags': { latest: '1.8.10', next: '2.1.0-dev.20160921', beta: '2.0.0', rc: '2.0.2' }rcbeta 更新,但也有 next - 每晚构建。 rc 的博客条目是 here
猜你喜欢
  • 2018-01-25
  • 2023-03-31
  • 2019-04-24
  • 2018-03-17
  • 2019-02-11
  • 2021-09-03
  • 2017-02-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多