-
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
Proposal: Modularize Library #6974
Comments
Thanks @yuit, great to see progress on this. I'm wondering about how this handles cases where there is crossover between features. For example, consider the following project setup: Example Project
interface PromiseConstructor {
...
all<T>(values: ArrayLike<T | PromiseLike<T>>): Promise<T[]>; // Do include this
all<T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>; // DO NOT include this
}
How to get just the right type definitions?For the above project, I'd like to tell I believe situations like this really get to the point of granular targeting. I've used How to handle feature crossover?I may have missed something, but I don't see any handling of feature crossover in this proposal as it is currently stated. It looks to me like the following would be the best that can be done:
This is where a |
@yortus Thanks for the feedback and pointing out some holes in the proposal.
Yes you are right that the current proposal when you pick feature such as So building upon your proposed solution, we can 1) separate symbol into its own file (probably same as iterator) 2) separate symbol in |
@yuit sounds reasonable :)
I agree there are definitely diminishing returns to supporting finer granularity. However, I do think the choice of "grains" should be informed by how the browsers/JS runtimes actually add feature support over time, which is what this issue is meant to address after all. For example, the So, while I would not suggest having a separate flag for each of the 2 dozen or so well-known symbols, I would suggest having a separate flag for
Agreed, the number and names of all these |
@alexeagle what you mean by lib.es6.* to be minimal? Do you mean you just want es5 lib? ( like what you describe in the issue #5504)? |
First preference would be to support If that's not possible for some reason, then I'd like to have the |
@alexeagle Thanks for the clarification. The new compiler flag will allow you to get your preference fix for #5504 😄 |
This should be fixed by #7715. |
Going through and adding to alm. I know it says Thanks! 🌹 |
More questions:
Here is a sample of the function I needed to delegate to eventually: export const getDefaultLibFilePaths = (options: ts.CompilerOptions): string[] => {
if (options.noLib) {
return [];
}
if (options.lib) {
/** Note: this might need to be more fancy at some point. E.g. user types `es6.array` but we need to get `es2015.array` */
return options.lib.map((fileName) => fileFromLibFolder(`lib.${fileName}.d.ts`));
}
return [fileFromLibFolder(ts.getDefaultLibFileName(options))];
} With this I have it working in alm. Feedback appreciated 🌹 |
In fact |
Verified by @2426021684 (TypeStrong/atom-typescript#918 (comment)) it is an array, as it should be 🌹 |
Update our decision on to ship node.d.ts or not to ship, the outcome is that we will not ship the node.d.ts as our default lib for the following reasons:
|
Problem
Currently TypeScript compiler accepts a single compiler option,
target
, which specify both version of library to be included during compilation and version of JavaScript for emitting code together.The behaviour presents limitations in two parts of the pipeline: consuming the default library and granularly controlling how JavaScript will be emitted (e.g. what features to be down-level etc.).
The proposal will mainly focus on the first issue regarding using the default library.
The current behavior of
target
option doesn't allow users to have a fine-grain control on what library or feature of the library to be included, and user cannot independently control library's version from emit JavaScript version. As summarized in #4692 Proposal: Granular Targeting and #4168 Normalize our lib files by compiler settingWorkaround
As @yortus points out in the #4692 Proposal: Granular Targeting , there are possible workarounds for above issues by maintaing customized version of the default library while
target
another version of emit JavaScript.Such approach is cumbersome to maintain and consume any necessary fixes of the default library.
Related Issues:
Proposed Solution
There are two parts to the proposed solution:
--lib
. The flag will be used to allow users to granularly control the default library.Note:
target
flag will remain. Its behaviors with--lib
flag will be discussed below.Compiler Flag
--lib
The flag's options (see below for the full list) allows users to specify what library to be included into the compilation.
The flag's options can be separated into following categories:
JavaScript only:
es3
es5
es6
Host only:
node
dom
dom.iterable
webworker
scripthost
ES6 or ESNext by-features options:
es6.array
es6.collection
es6.function
es6.generator
es6.iterable
es6.math
es6.number
es6.object
es6.promise
es6.proxy
es6.reflect
es6.regexp
es6.string
es6.symbol
es6.symbol.wellknown
es7.array.include
The
--lib
flag is an optional flag and multiple options can be used in combination (e.g--lib es6,dom.iterable
) and each option will be mapped to associated library.So in this example, files:
lib.es6.d.ts
andlib.dom.iterable.d.ts
will be loaded into the compilation..When
--lib
is specified,--target
will be used solely to indicate version of emitting JavaScript.In additional to above behavior, we still need to determine what to be included when
--lib
is not specified, should it remain the same, including version of library specifying by--target
and all host libraries, or including every library. -> _Current implementation is to include version of the library using--target
The proposal will only affect when the compiler attempts to create compilation in Program.ts. Other parts of the pipeline will not be affected by the proposal.
Usage:
The
--lib
flag will take an options in the form of string separated by comma. Space will not be allowed as a separator. This rule apply to both command line and tsconfigValid
Invalid command-line
Working Items:
The text was updated successfully, but these errors were encountered: