npm @types 包的类型 globalDevDependencies 的等效性是什么? [英] What's the equivalence of typings globalDevDependencies for npm @types packages?

查看:65
本文介绍了npm @types 包的类型 globalDevDependencies 的等效性是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 tsc@1.8 项目升级到 tsc@2 并在此过程中从我的工具链中删除 typings.

I want to upgrade an tsc@1.8 project to tsc@2 and in the process ditch typings from my tool chain.

对于常见的依赖来说这不是问题,因为这些依赖来自我的 typings.json:

It's not a problem for the common depencies as these dependencies from my typings.json:

"dependencies": {
  "bluebird": "registry:npm/bluebird#3.3.4+20160515010139",
  "lodash": "registry:npm/lodash#4.0.0+20160416211519",
  "mime": "registry:npm/mime#1.3.0+20160423043021"
}

我可以通过

npm i @types/bluebird @types/lodass @types/mime

然而,我的 typings.json 中还有一些 globalDevDependencies 用于我的测试设置:

Yet I also have some globalDevDependencies for my test setup in my typings.json:

"globalDevDependencies": {
  "mocha": "registry:dt/mocha#2.2.5+20160317120654"
}

我的第一次尝试是:

npm install @types/mocha --save-dev

但现在 tsc 抱怨它不知道 mocha 函数 itdescribe.

Yet now tsc complains it doesn't know the mocha functions it and describe.

tests/unit/HelloServiceTest.ts(4,1): error TS2304: Cannot find name 'describe'.
tests/unit/HelloServiceTest.ts(5,5): error TS2304: Cannot find name 'it'.
tests/unit/HelloServiceTest.ts(10,5): error TS2304: Cannot find name 'it'.

长期来看,我错误地认为全局安装这些可能会解决问题:

As a longshot I mistakenly thought installing those globally might resolve the issue:

npm i @types/mocha  -g

我还偶然发现了这个问题,解决方案是不排除tsconfig.json 中的 types 文件夹:

I also stumbled across this issue where the solution was to not exclude the types folder in the tsconfig.json:

"exclude": [
    "node_modules",
    "!node_modules/@types"
]

但它对我也不起作用,抛出同样的错误.

yet it also didn't work for me, throwing the same error.

最后,我不知道如何实现与 typings' globalDevDependenciesglobalDependencies 相同的效果只使用 npm@types/* 包而不是 typings.

In the end, I don't know how to achieve the same effect that typings' globalDevDependencies and globalDependencies had when I want to use just npm and the @types/* packages instead of typings.

推荐答案

这个线程 为我指明了正确的方向,因为我必须将类型添加到 tsconfig.json 中:>

This thread pointed me in the right direction, as I have to add the types to the tsconfig.json:

{
  "compilerOptions": {
    "target": "ES6",
    "types": ["node", "mocha", "chai"],
    ...
}

类型选项也有一个冗长文档.

这篇关于npm @types 包的类型 globalDevDependencies 的等效性是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆