Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for BrowserList and Core-JS Polyfills Automatically #20095

Closed
RehanSaeed opened this issue Nov 17, 2017 · 11 comments
Closed

Add Support for BrowserList and Core-JS Polyfills Automatically #20095

RehanSaeed opened this issue Nov 17, 2017 · 11 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@RehanSaeed
Copy link

RehanSaeed commented Nov 17, 2017

Babel provides the babel-preset-env plugin which uses the [browserlist] syntax shown below to automatically add pollyfills from core-js. This looks at the browsers you want to support and automatically adds the required pollyfills. Babel even goes as far as recommending this approach.

>1%
Last 4 versions

I never want to have to think about which pollyfills I need to add, TypeScript should provide a typescript-preset-env NPM package to do this for you as it's a very common scenario and easily prone to error. TypeScript should support the browserlist format directly in the tsconfig.json file or in a separate .browserlistrc file.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 18, 2017

that is what --lib do.. anything specifically you are missing?

@mhegazy mhegazy added the Needs More Info The issue still hasn't been fully clarified label Nov 18, 2017
@RehanSaeed
Copy link
Author

The lib option does not polyfill anything. It simply tells TypeScript to assume that certain API's are available. Babel goes further than the lib option and automatically polyfills too.

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@RehanSaeed
Copy link
Author

Can this be reopened? This issue is marked as 'Need more info' which I've already supplied. I think I've layed out my proposal clearly.

@levenleven
Copy link

Would be nice to have auto polyfilled everything that is specified in --lib and used in code base

@kitsonk
Copy link
Contributor

kitsonk commented Dec 5, 2017

No it wouldn't... There are many ways to provide functional polyfills and assuming one size fits all would be anti-pattern for TypeScript, as it is a syntactical compiler. In particular it contravenes the following non-goal:

  1. Provide additional runtime functionality or libraries. Instead, use TypeScript to describe existing libraries.

Also it touches on this non-goal:

  1. Provide an end-to-end build pipeline. Instead, make the system extensible so that external tools can use the compiler for more complex build workflows.

Which is entirely consistent with the approach of the language to this point. TypeScript can be forced to assume some functionality is available (like Promise or Symbol) and use those, but does not provide any functional polyfills.

@sebinsua
Copy link

Does the TypeScript team disagree with the approach being taken by babel-preset-env#useBuiltins then?

I think this issue should be re-opened to properly discuss this.

@RehanSaeed
Copy link
Author

RehanSaeed commented Feb 21, 2018

Babel is TypeScript's major competitor and provides this functionality as a separate package and even recommends using babel-preset-env. If you use Babel, you do not wake up at night in sweats thinking about polyfills.

TypeScript could add this functionality by providing a similar typescript-preset-env NPM package. As it stands, TypeScript developers working in the browser have to get deep into core-js and other pollyfills to get their work done. This is the one area where the grass on the Babel side is far greener.

@stereobooster
Copy link

Babel is TypeScript's major competitor

I don't think so. Babel has no type system.

I suppose this is the official solution to the problem https://github.com/Microsoft/TypeScript-Babel-Starter

@RehanSaeed
Copy link
Author

@stereobooster It doesn't matter that Babel doesn't have a type system. When a developer decides what front end language to use today, the chances are that they choose between Babel and TypeScript. Other languages come a distant third.

Thanks for the interesting link 🥇 , JS type checking is a half way house, you'll catch some errors but not all.

@Ciantic
Copy link

Ciantic commented Apr 4, 2018

While this might be out of scope of TypeScript, I would like to chime in. I came here because I thought like this:

Since TypeScript knows the types (and calls) it can infer the required polyfills. E.g. if user uses

[1,2,3,4].includes(3)

TypeScript knows this, so it could add includes polyfill. Or mark it as required.

Maybe some other tool could then add all the required polyfills once the TypeScript has collected them.

However, I note that this could be implemented as a tool completely separate from TS.

@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

8 participants