简体   繁体   English

如何安装与较早版本的TypeScript兼容的@types?

[英]How can I install @types compatible with an older version of TypeScript?

My project uses package like @types/express and @types/body-parser . 我的项目使用像@types/express@types/body-parser Recently these .d.ts files were updated to use generic defaults, but that means these declaration files now require TypeScript 2.3 or above. 最近,这些.d.ts文件已更新为使用通用默认值,但这意味着这些声明文件现在需要TypeScript 2.3或更高版本。

However, my project still uses an older version of TypeScript - TypeScript 2.2. 但是,我的项目仍然使用TypeScript 2.2的旧版本。 How do I use npm to make sure my project can still understand these definition files without upgrading? 我如何使用npm确保我的项目无需升级就可以理解这些定义文件?

The @types publisher tool actually tags releases based on compatibility. @types发布者工具实际上基于兼容性来标记发布。

To be able to install declaration files that are compatible with TypeScript 2.2, you can write 为了能够安装与TypeScript 2.2兼容的声明文件,您可以编写

npm install @types/body-parser@ts2.2

It's not always perfect, but it'll usually get the job done. 它并不总是完美的,但通常可以完成工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM