es6和es2017之间tsconfig.json中'lib'属性的区别? [英] Difference in the 'lib' property in tsconfig.json between es6 and es2017?

查看:1670
本文介绍了es6和es2017之间tsconfig.json中'lib'属性的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究 lib 属性的可能值在 compilerOptions code> tsconfig.json 文件。我在 Typescript GitHub 页面上找到相关的 d .ts 与这些值相对应的文件,显然使用 ES2017 包括以下ES功能:

  ///< reference path =lib.es2016.d.ts/> 
///< reference path =lib.es2017.object.d.ts/>
///< reference path =lib.es2017.sharedmemory.d.ts/>
///< reference path =lib.es2017.string.d.ts/>
///< reference path =lib.es2015.d.ts/>
///< reference path =lib.es2016.array.include.d.ts/>
///< reference path =lib.es2015.core.d.ts/>
///< reference path =lib.es2015.collection.d.ts/>
///< reference path =lib.es2015.generator.d.ts/>
///< reference path =lib.es2015.iterable.d.ts/>
///< reference path =lib.es2015.promise.d.ts/>
///< reference path =lib.es2015.proxy.d.ts/>
///< reference path =lib.es2015.reflect.d.ts/>
///< reference path =lib.es2015.symbol.d.ts/>
///< reference path =lib.es2015.symbol.wellknown.d.ts/>
///< reference path =lib.es5.d.ts/>

但显然ES6不包括在内,并且拥有自己的文件。我的问题是,如果有人知道,可以安全地假设使用 es2017 我覆盖所有的 es6 功能(或者应该分别包含在 lib 选项中?



例如,像这样:

  {
...
compilerOptions:{
...
lib:[es2017,dom]
},
...
}
}
/ pre>

或者这个:

  {
。 ..
compilerOptions:{
...
lib:[es2017,es6,dom]
},

}
}


解决方案

通过 lib 文件夹进行一些挖掘和比较后,rel = nofollow noreferrer> Typescript GitHub 我发现在 lib 属性中使用 es6 compilerOptions 对应于这些引用中的代码:

  ///< reference path =lib.es2015.core.d。 ts/> 
///< reference path =lib.es2015.collection.d.ts/>
///< reference path =lib.es2015.generator.d.ts/>
///< reference path =lib.es2015.iterable.d.ts/>
///< reference path =lib.es2015.promise.d.ts/>
///< reference path =lib.es2015.proxy.d.ts/>
///< reference path =lib.es2015.reflect.d.ts/>
///< reference path =lib.es2015.symbol.d.ts/>
///< reference path =lib.es2015.symbol.wellknown.d.ts/>
///< reference path =lib.es5.d.ts/>
///< reference path =lib.dom.d.ts/>
///< reference path =lib.scripthost.d.ts.d.ts/>
///< reference path =lib.dom.iterable.d.ts/>

所以回答我的问题,正确地覆盖 es6 es2017 tsconfig.json的该部分应如下所示:

  {
...
compilerOptions:{
...
lib:[es2017,dom,dom可执行的,scripthost]
},
...
}
}


I've been researching what the possible values of the lib property mean in the compilerOptions found within the tsconfig.json file. I found on the Typescript GitHub page the relevant d.ts files corresponding to those values and apparently by using ES2017 the following ES features are included:

/// <reference path="lib.es2016.d.ts" />
/// <reference path="lib.es2017.object.d.ts" />
/// <reference path="lib.es2017.sharedmemory.d.ts" />
/// <reference path="lib.es2017.string.d.ts" />
/// <reference path="lib.es2015.d.ts" />
/// <reference path="lib.es2016.array.include.d.ts" />
/// <reference path="lib.es2015.core.d.ts" />
/// <reference path="lib.es2015.collection.d.ts" />
/// <reference path="lib.es2015.generator.d.ts" />
/// <reference path="lib.es2015.iterable.d.ts" />
/// <reference path="lib.es2015.promise.d.ts" />
/// <reference path="lib.es2015.proxy.d.ts" />
/// <reference path="lib.es2015.reflect.d.ts" />
/// <reference path="lib.es2015.symbol.d.ts" />
/// <reference path="lib.es2015.symbol.wellknown.d.ts" />
/// <reference path="lib.es5.d.ts" />

But apparently ES6 is not included and has it's own file that doesn't reference anything. My question is, if anybody knows, is it safe to assume that by using es2017 I cover all the es6 functionality (from a typings perspective) or should that be included separately in the lib option?

For example, like this:

{
  ...
  "compilerOptions": {
    ...
    "lib": ["es2017", "dom"]
  },
  ...
  }
}

OR this:

{
  ...
  "compilerOptions": {
    ...
    "lib": ["es2017", "es6", "dom"]
  },
  ...
  }
}

解决方案

After some digging and comparing through the lib folder on the Typescript GitHub I have found that, using es6 in the lib property in the compilerOptions corresponds to the code found in these references:

/// <reference path="lib.es2015.core.d.ts" />
/// <reference path="lib.es2015.collection.d.ts" />
/// <reference path="lib.es2015.generator.d.ts" />
/// <reference path="lib.es2015.iterable.d.ts" />
/// <reference path="lib.es2015.promise.d.ts" />
/// <reference path="lib.es2015.proxy.d.ts" />
/// <reference path="lib.es2015.reflect.d.ts" />
/// <reference path="lib.es2015.symbol.d.ts" />
/// <reference path="lib.es2015.symbol.wellknown.d.ts" />
/// <reference path="lib.es5.d.ts" />
/// <reference path="lib.dom.d.ts" />
/// <reference path="lib.scripthost.d.ts.d.ts" />
/// <reference path="lib.dom.iterable.d.ts" />

so to answer my question, to correctly cover all the contents of es6 with es2017 that section of the tsconfig.json should look like this:

{
  ...
  "compilerOptions": {
    ...
    "lib": ["es2017", "dom", "dom.iterable", "scripthost"]
  },
  ...
  }
}

这篇关于es6和es2017之间tsconfig.json中'lib'属性的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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