-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Comments
that is what |
The lib option does not polyfill anything. It simply tells TypeScript to assume that certain API's are available. Babel goes further than the |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
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. |
Would be nice to have auto polyfilled everything that is specified in |
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:
Also it touches on this non-goal:
Which is entirely consistent with the approach of the language to this point. TypeScript can be forced to assume some functionality is available (like |
Does the TypeScript team disagree with the approach being taken by I think this issue should be re-opened to properly discuss this. |
Babel is TypeScript's major competitor and provides this functionality as a separate package and even recommends using TypeScript could add this functionality by providing a similar |
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 |
@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. |
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
TypeScript knows this, so it could add 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. |
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.
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 thetsconfig.json
file or in a separate.browserlistrc
file.The text was updated successfully, but these errors were encountered: