Skip to content

Using ES6 type default library when targetting ES5 output #3005

Closed
@robertknight

Description

@robertknight

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions