Closed
Description
I'm building a project for 'modern' but not bleeding-edge browsers (IE >= 10, Chrome/Firefox from mid-last year onwards), this means targeting ES5 output since ES6 language features are incomplete. However I'm able to use many ES6 library features either via polyfills (Map, Set, Promise) or because browsers added support for them early on (eg. DataView is available in IE 10 and later).
At the moment the language and library targets in TSC are controlled by the same --target option, which makes this difficult, more so in TS 1.5.0-beta because a number of ES6 APIs that used to be in the lib.d.ts file (Map, DataView) are now only found in the ES6 library.
Some possible solutions:
- Always make ES6 type definitions available - leave it up to TSC users to determine what APIs they can target.
- Put all the type definitions in the same file, but provide a way to annotate methods which are part of a given ES-version. eg. Rust allows annotations like
#[stable(feature = "rust1", since = "1.0.0")]
on a method to indicate which version of the library a method became available in. Compiler flags could then be used to allow or deny use of ES6 interfaces. - A simple compiler switch that specifies the library target, separately from the language/emit target.
Thoughts?