4
votes

TypeScript compiler has the following options for the --lib cmd line arg:

  • ES2018
  • ES2018.Promise
  • ES2018.RegExp

What is the difference between them? Should I use ES2018 or ES2018.Promise if I need Promisefinally() support only and do NOT care about other ES2018 features?

Also, since what TS version those ES2018 libs are supported? When I try to use them with TS 2.6.2, it throws:

Error: tsconfig.json(16,13): error TS6046: Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'esnext.asynciterable'.

1
Correct. ES2018 includes AFAIK object rest, Promise.finally, and the regex stuff: named capture groups, lookbehinds, s-flag, and unicode script attributes.Jared Smith

1 Answers

1
votes

The lib option only provide typing for these libraries. If you specify ES2018 than you will get ES2018 typing even if you target for ES2015. By default, TypeScript sets some libs depending on which target you specify but it allows you since version 2.0 to manually add more typing.

What is the difference between them?

They are a subset of different families of features.

Should I use ES2018 or ES2018.Promise if I need Promisefinally() support only and do NOT care about other ES2018 features?

Yes, you are can scope to what you need. However, it won't increase your generated JavaScript if you include more.

Since what TS version those ES2018 libs are supported?

If you are using a target that does not support a feature natively, you may download (npm) a package to Polyfill. It's not related directly to a TS version.