如何安装与旧版 TypeScript 兼容的 @types? [英] How can I install @types compatible with an older version of TypeScript?
问题描述
我的项目使用@types/express
和@types/body-parser
之类的包.最近这些 .d.ts
文件被更新为使用通用默认值,但这意味着这些声明文件现在需要 TypeScript 2.3 或更高版本.
My project uses package like @types/express
and @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.
但是,我的项目仍然使用旧版本的 TypeScript - TypeScript 2.2.如何使用 npm 确保我的项目在不升级的情况下仍然可以理解这些定义文件?
However, my project still uses an older version of TypeScript - TypeScript 2.2. How do I use npm to make sure my project can still understand these definition files without upgrading?
推荐答案
@types
发布者工具实际上根据兼容性标记发布.
The @types
publisher tool actually tags releases based on compatibility.
为了能够安装兼容TypeScript 2.2的声明文件,可以写
To be able to install declaration files that are compatible with TypeScript 2.2, you can write
npm install @types/body-parser@ts2.2
它并不总是完美的,但通常可以完成工作.
It's not always perfect, but it'll usually get the job done.
这篇关于如何安装与旧版 TypeScript 兼容的 @types?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!