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"]
},
...
}
}
TypeScript includes a default set of type definitions for built-in JS APIs (like Math ), as well as type definitions for things found in browser environments (like document ).
Small addition to other answers: @types property in tsconfig.json is used mostly for global declarations (logic which you can use without import ing modules). So, it won't limit your types if you import . E.g. you have this package: node_modules/@types/foo .
You can find a set of community organized TSConfigs at tsconfig/bases, which has configurations for common platforms and their versions. The special ESNext value refers to the highest version your version of TypeScript supports.
The "include" property allows you to include a list of TypeScript files using the glob wildcards pattern. The "exclude" property allows you to exclude a list of TypeScript files using the glob wildcards pattern.
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"]
},
...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With