-
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
Better compile time polyfill support by splitting lib .d.ts files into smallest segments possible #25567
Comments
My opinion is that it would sort of make things unmanageable. I would think that if you are microfilling in such ways, that declaring the types yourself as part of the microfilled code base would be best. ES2015 is already broken down into core, generator, promise, iterable, proxy, reflect, symbol, and symbol.wellknown. I am not sure breaking them down further would realistically add value. |
One thing to note the library files are not special in any way. they are just regular .d.ts files with declarations in them. Nothing stops you from adding your set of lib files that have the declarations you use and pull them as needed. the JS runtime does not change that much, so it should be a one-time setup cost, and you should be fine. We have split them in logical units to make it manageable to pull them in/out. we can split them into file-per-function, but there are APIs that have multiple overloads, e.g. ones that have iterable vs array (e.g. |
@mhegazy so a little more context on our situation. There are a couple hundred web developers working on (at last count) 150+ web modules (mostly shared packages but there are a couple web apps). So whatever solution we use needs to scale. Your right we could create a "common typings" project and duplicate the exiting deceleration files and split them into smaller segments for our use there. I was hoping to avoid creating a custom solution like this since my thinking was that this is a common enough problem that it made sense to try and do this work in a place that would benefit all TS users. To be clear I am not advocating for the removal of the exiting logical units, I am just asking that the existing logical units be compositions of smaller units that can be imported on their own. So using the existing"es2015.core.d.ts" as an example it would become a composition of the following files (or something like this, maybe with kebab casing),
You bring up a good point about how their are some functions which require overloads as new features are brought in. I believe we can resolve this by making sure the interfaces for those types are defined independent of the polyfill. For example for Unfortunately, this will result in the defined types for existing projects using "es2015.core" or "es2015.iterable" would change slightly. Not as equivalent for existing users as I originally though. Happy to do the work to get this setup as this is a huge pain point for folks at my company. For those of us who need to support old browsers compile time checking is very useful to make sure we do not miss any polyfills. When you say your worried about the complexity are you concerned that it will be difficult to reason about from the perspective of a user of TS? Or from the perspective of the developers of TS? |
I would say both. Complexity is always measured relative to gain, and this isn't a) a broadly-requested feature or b) something you couldn't do today by running with We also have to think about complexity in terms of the future. If we look ahead 15 years, are we going to be looking at loading 600 different files from disk just for "Hello World" because every single function TC39 added gets its own file? That has performance implications and maintainability implications. |
How many times does it need to be requested before it matters? ;) |
@RyanCavanaugh I hear you on trying to be aware of your maintenance and performance cost. Personally I think its a little early to say that this will have any impact on performance or TS's long term maintenance story. For perf hundred's of file reads occur today as part of compile, it is the same order of magnitude of file reads with this proposed change. I find talking about long term theoretical's like this difficult because there is nothing to say that the existing solution won't have the same problem you describe as with this proposed solution. I guess my value argument essentially boils down to this: |
Does because people keep asking for something doesn't always make it the right thing to do. 😉
I think there is nothing preventing any interesting parties doing the work as a thought experiment and reporting back the impact on performance. It is an open source project after all. There is a question of the core team expending an effort on it though versus working on other things. |
I have not seen other requests for this kind of thing, nor scenarios that would benefit from it, and given the large implications of it, this won't be something we take up. |
Search Terms
lib, polyfill
Suggestion
Split the existing lib .d.ts files into smaller feature segments so each feature can be included selectively as desired.
Use Cases
I work at a company with a large collection of independently shipping web modules/apps.
Today we use the following method to detect at compile time if a polyfill will be required for the browsers we support (IE11+ in our case).
The problem is that the current definitions for tsconfig.json lib are often much larger then we would like.
For example:
If we want to use the feature
Array[].findIndex
using this above described method we would add "es2015.core" to the tsconfig.json and a correspondingArray[].findIndex
polyfill. This works but unintentionally results in a plethora of other features (Array.find
,Array.from
, ...) that now will compile without problems but are not polyfilled.If we want to be sure to avoid unintentionally using a "es2015.core" feature we have not polyfilled we would have to polyfill all of the features but would really like to avoid doing that.
Examples
Would be great if the type definitions were split in a similar way to core-js. They do a fantastic job of allowing selective polyfills as well as collections of polyfills.
so for the array methods "es2015.core" would be split into "es2015.array" which would be a composition of independently usable more specific cases (for example "es2015.array.findIndex").
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: