简体   繁体   English

可以更改TypeScript CompilerOptions-> lib与NPM软件包或依赖项的冲突

[英]Can changing TypeScript compilerOptions->lib conflict with NPM Packages or Dependencies

I have a question about the compilerOptions->lib property in tsconfig.json . 我对tsconfig.json中的tsconfig.json > lib属性有tsconfig.json

Situation is I'm working on a Firebase Cloud Functions project written in TypeScript and I need the method Array.prototype.includes() . 情况是我正在处理用TypeScript编写的Firebase Cloud Functions项目,并且需要使用Array.prototype.includes()方法。 But I was unable to build because includes() was not supported, a quick Google search showed I only had to change lib from ES6 to ES2016 which changes the version of Ecmascript. 但是我无法构建,因为不支持include(),谷歌快速搜索显示我只需要将lib从ES6更改为ES2016即可更改Ecmascript的版本。

My question is. 我的问题是。 Does changing the lib property do anything besides giving me newer/more functionality? 除了为我提供更新/更多功能之外,更改lib属性是否还能做任何事情?

I'm worried if it somehow might conflict with Firebase Cloud Functions or the NodeJS version I'm using or NPM packages/dependencies. 我担心它是否可能与Firebase Cloud Functions或我正在使用的NodeJS版本或NPM软件包/依赖项冲突。

No the lib flag doesn't change the output of the Typescript compiler, the target flag does that. 没有lib标志不会改变Typescript编译器的输出,而target标志会这样做。

lib simply includes the typings of the library versions you specify in the compilation process, so that compiler won't complain. lib仅包含您在编译过程中指定的库版本的类型,以便编译器不会抱怨。 (These typings could be found under node_modules\\typescript\\lib) (这些类型可以在node_modules \\ typescript \\ lib下找到)

If your target runtime doesn't support the functions you use (includes() in this case), its your responsibility to provide it using a polyfill. 如果目标运行时不支持您使用的功能(在这种情况下为includes()),则您有责任使用polyfill提供它。 Typescript doesn't actually include the library for you in the compiled output. Typescript实际上不会在编译输出中为您提供库。

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

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