-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Normalize our lib files by compiler settings #4168
Comments
A really common practice right now is compiling for ES5, but still needing ES6 Breaking down the stdlib files into more parts could help work towards this considerably. |
so what is the granularity, what needs to be in a flle by itself and what is not.. also what is draw back from just including all es6 types? |
Including ES6 types would drop many extra types into your IDE/Editor experience which you don't actually have access to in your targeted environment, for one. Beyond that, many awkward things (interface redefinitions and the like) happen when you try to depend on a partial ES6 polyfill |
I agree with the principal, my question is about the details.. what is the granularity? is it down to methods (es6.array.is.d.ts) or containers (es6.array.d.ts, es6.object.d.ts), or areas (es6.core.d.ts, es6.typedarrays.d.ts, es6.promise.d.ts)? |
If we can get away with it, the highest level of granularity possible will allow the greatest amount of compiler consumer control later (and also combinatoric expansion in possible compiler configurations). Generally speaking though, I'd say I'm partial to group by feature area (like how babel groups language features), since it's seemed like that's how they've gotten implemented in JS environments - one feature at a time. (Eg, the 'Set' API, the 'Map' API, the new 'Array' API, etc.) |
If more granuar targetting is on the cards, then some consideration ought to be given to emit, not just lib files, for precisely the same motivations. As @weswigham points out, JS environments implement and release features incrementally. Babel reflects this reality. With TypeScript one must choose the lowest common denominator for the target, even if the environment supports many but not all features of a higher target. Otherwise the emitted code will not run on the target. For example its still prudent to target ES5 for node projects, even though V8 now supports a great many ES6 features. My suggestion would be to add a key to {
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"targets": {
"builtins.map": "es6",
"builtins.weakMap": "es6",
"syntax.arrowFunctions": "es6",
"syntax.generators": "es6",
"syntax.templateStrings": "es6"
}
}
} So a project can have a default target, and then override targets for particular features it uses. Note that 'features' cover far more than just |
How would this work with something that crosses features like symbols, which would add members to other types that may or may not be there? For example, the presence of "builtins.symbol" cannot naively result in |
I imagine Symbols are a little interesting since a full implementation of them touches a lot of other objects... regexes, arrays, etc... but those well-known symbols aren't always present depending on the target('s implementation status), so being able to choose the ones you know will exist is a good thing. |
I made a proposal for a possible solution over at #4692. There is a working implementation too. |
I like this approach, but will I be able to define a new host? TypeScript should not hardcode the possible hosts my code can run in but provide a solution where I can provide my own host. To give an example: Electron is a host for JavaScript that adds API on top of plain JS and node.js. Specific versions of Electron might have different API. I want to express in my tsconfig.json that the host is "Electron: 0.34.x". |
I do not think we can do a generic support for all hosts, the ones we know about are "core", i.e. some ES3/ES5/ES6 compliant engine (things like Object, JSON, Error, etc..), and "DOM" (regular and webworker, only latest, version would not possible here). for anything else, you need to pass a .d.ts for your host. so you should have |
subsumed by #6974 |
Hi guys, I'm getting:
Only in one version of node (6.5.0 x86) with tsify. I'm not sure about what is causing the issue but I'm using:
Any ideas? Full details available at tsify/issues/196. Thanks! |
do you happen to have |
I'm using |
This is likely a |
Thanks for helping me out @RyanCavanaugh @mhegazy it is now confirmed as a tsify bug. |
Thanks! |
Oops |
Right now the compiler depends on a monolithic
lib.d.ts
file that is resolved according to the script target (ES5 or ES6). We have to build several different lib.d.ts files out of smaller parts.We should refactor this so that the different aspects of the compiler settings can map to smaller sub-parts of the libraries.
Language target:
Host:
Module system:
The idea is that we a function that takes a CompilerSettings and produces a list of filenames. These files might reference each other, e.g.
lib.es5.d.ts
would probably referencelib.es6.d.ts
and just provide interface augmentations.This provides several benefits:
The text was updated successfully, but these errors were encountered: