-
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
Add es3.d.ts #16077
Add es3.d.ts #16077
Conversation
91cad46
to
cc9a133
Compare
Gulpfile.ts
Outdated
{ target: "lib.es5.d.ts", sources: ["header.d.ts", "es5.d.ts"] }, | ||
{ target: "lib.es2015.d.ts", sources: ["header.d.ts", "es2015.d.ts"] }, | ||
{ target: "lib.es2016.d.ts", sources: ["header.d.ts", "es2016.d.ts"] }, | ||
{ target: "lib.es2017.d.ts", sources: ["header.d.ts", "es2017.d.ts"] }, | ||
{ target: "lib.esnext.d.ts", sources: ["header.d.ts", "esnext.d.ts"] }, | ||
|
||
// JavaScript + all host library | ||
{ target: "lib.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(hostsLibrarySources) }, | ||
{ target: "lib.d.ts", sources: ["header.d.ts", "es3.d.ts"].concat(hostsLibrarySources) }, | ||
{ target: "lib.es5.full.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(hostsLibrarySources) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would keep lib.d.ts to be es5 and create lib.es3.full
just to avoid breaking users how depend on a specific meaning of lib.d.ts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. (It was intended to suppress baseline changes.)
@rbuckton mind taking a look at the lib changes. |
I included typed arrays in es3.d.ts as:
We probably can move their constructors to es2015.d.ts, similar to what's done for Promises. |
On
|
@ericdrobinson Promise initially was not on es5.d.ts, it moved later by #14053. The sole purpose of including Promise and Typed Arrays to prevent errors from lib.dom.d.ts where APIs e.g. Fetch and Web Audio use them. If the types are removed from es3 then users will get errors every time they build for ES3 target. I think you won't be confused too much for Promise as the Promise constructor is intentionally only supported on ES2015+, which means you cannot do |
How is this not resolved by moving them to a separate type document that lib.dom.d.ts is aware of? You could specify this separately in the gulpfile. As an example, let's say everything was cleanly returned to es2015.promise.d.ts. Could you not, then, simply adjust the lib.dom.d.ts specification to use: { target: "lib.dom.d.ts", sources: ["header.d.ts", "dom.generated.d.ts"].concat("es2015.promise.d.ts") }, I do not know enough, currently, about the state of Promises to say whether or not this is the correct path or if a separate dom.promise.d.ts file should be made and referenced, rather than the es2015-specific version. However, this would allow for a clean es3 and/or es5 specification. Am I missing something critical here? |
I expanded upon this a bit in #16132. |
But this does not apply for Pretty much everything below this line is merely included as a kludge to assist in supporting other, dependent libraries. This kludge is a hold-over from a time before the |
I think it's somehow doable, but probably with another PR (as this one already has many baseline changes). I will talk more on #16132. |
TL;DR - Could you at least move all types below this line back into the ES5 lib? That would leave the default setting (lib.d.ts) unchanged, while allowing more granular (and correct) environment configuration for users who need ES3...
When you initially wrote the ES3 library you also changed it to be the default library imported by lib.d.ts. That has subsequently changed. With that change, a user wishing to use ES3 must specify as much using the "lib": ["es3"] For a user who wishes to also use DOM APIs, they would need to specify: "lib": ["es3", "dom"] I should clarify that this is decidedly not a problem. It works as expected. However, now that ES5 has been switched back to being the default, the kludge of including the DOM support types can be moved back into "es5", right? What this would mean for someone wishing to use an ES3+DOM environment is that they would have to specify the following: "lib": ["es3", "dom", "es2015.promise.d.ts"] Such users would have access to the [decidedly bloated] DOM APIs but could still code with ES3. They would of course end up with Promises in their types, but this is a side-effect of using the monolithic DOM library, not an incorrectly formed ECMAScript type library. By keeping the ES3 lib to types only specified in the ECMAScript 3 language specification, you can still have ES5 use it as a base and better support environments that are strictly ES3-based (including ExtendScript). |
No,
As |
Perhaps I don't understand how
First, where is a good entrypoint in the codebase for understanding how Second, if for whatever reason, compilation breaks when you don't include the For that matter, |
If you look at the es2015.promise.d.ts it only contains Promise constructor type, not Promise instance type. Adding it on lib.es3.full.d.ts will unexpectedly allow
Yes it used es5 lib, and will be changed because there were some valid requests for this. |
Thanks. This is very helpful. Came just as I located this note in the code where it actually gets used. I feel I have a more complete understanding now.
Ahh, yes, the "fix" for that is back over in #16132. Such a fix would require implementing (even if temporarily) one of the fixes suggested there.
I understand that specifying |
I would name it |
That makes sense. As much as it might feel "more correct" to move the offending type declarations into their respective es2015 libraries (e.g. |
/** | ||
* Provides functionality common to all JavaScript objects. | ||
*/ | ||
declare const Object: ObjectConstructor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ES3 spec does not declare these as const
. Doing so would prevent shim libraries from being able to replace globals in TypeScript. Generally I think these should stay as var
.
@DanielRosenwasser, do you have an opinion here?
new (byteLength: number): ArrayBuffer; | ||
isView(arg: any): arg is ArrayBufferView; | ||
} | ||
declare const ArrayBuffer: ArrayBufferConstructor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typed Arrays are not part of ES3 or ES5. We included them in ES5 to support the DOM. One option to still support ES3 and not break the DOM lib would be to have the interfaces present in the ES3 lib, but leave the constructor declarations (e.g. declare var ArrayBuffer: ArrayBufferConstructor
) in ES5 for now. That way, the types exist at design time but you cannot actually create an instance as there is no value declaration.
This is the approach we took for Promise
. The interface for Promise
was moved to ES5, but the value declaration was left in es2015.promise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rbuckton Did you perchance read over the comments on this topic in the thread? Would be interested in your thoughts as to why these shouldn't simply be moved to a separate document altogether that's included in the "full" versions of the libs, rather than the core ones. See this post and several preceding it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did see the thread, yes. We may eventually want to break those down into their own libs, but include them in the default lib in some fashion. I'd also like to be able to break down lib.dom.d.ts, but it is currently auto-generated and such a breakdown would be cumbersome at this point.
I've started investigating this as part of #15780, however that need not block this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also like to be able to break down lib.d.ts, but it is currently auto-generated and such a breakdown would be cumbersome at this point.
Would it really be that cumbersome? Wouldn't that simply involve adding a lib.es2015.dom.d.ts
file to the src/lib directory and then adjusting the lib.d.ts (and others) to make use of it?
I've started investigating this as part of #15780
I take it that this would imply changing the system such that a lib.d.ts file actually existed within src/lib folder and used the new lib
keyword to bring in the types, rather than compile it together as part of a build step?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also like to be able to break down lib.d.ts, but it is currently auto-generated and such a breakdown would be cumbersome at this point.
Would it really be that cumbersome? Wouldn't that simply involve adding a
lib.es2015.dom.d.ts
file to the src/lib directory and then adjusting the lib.d.ts (and others) to make use of it?
You either misread or misquoted me. I did not say lib.d.ts would be cumbersome, but rather that lib.dom.d.ts would be as it is auto-generated. The tool that does this doesn't have a mechanism to break down features by which ECMAScript edition is supported. I don't know how much effort changing that would entail, but I do know that it is not insignificant.
I take it that this would imply changing the system such that a lib.d.ts file actually existed within src/lib folder and used the new
lib
keyword to bring in the types, rather than compile it together as part of a build step?
Roughly, yes. See src/lib/default.es5.d.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You either misread or misquoted me.
Yup. A little from column A; a little from column B, to be sure. Sorry about that!
I did not say lib.d.ts would be cumbersome, but rather that lib.dom.d.ts would be as it is auto-generated. The tool that does this doesn't have a mechanism to break down features by which ECMAScript edition is supported.
Ahh, I see. Perhaps, then, you misunderstood or misread the discussion above? We were not discussing the option of moving the TypedArray
, Promise
, etc. types back into lib.dom.d.ts
, but rather to a separate support lib (lib.es2015.dom.d.ts
or dom.support.d.ts
or what-have-you); one who's purpose would be to provide the default "full" libraries with the necessary types. At the end of the day, this would result in no change to the default setup or the "full" libraries, only allowing the ES3 and ES5 libs to be, well, spec-compliant. The DOM/ECMAScript feature matrix should still be handles separately.
Please take a look at #16132. It details how many of the non-ECMAScript based "support" types came into the picture and when. The idea here is to move those types out of the (ex-core
) ES3/ES5 context and into a separate "bandaid" library, which would allow ES3, ES5, etc. libraries to properly conform to the specs.
Part of the reason that I'm pushing for a move like this is that
- It does not appear to be difficult to arrange the code this way,
- it truly highlights an issue with the current setup and begins to isolate "problem code" such that a future fix will involve removing this "sore spot", and
- helps clean up the ES3 and ES5 libraries, which only contain several of those types because they initially evolved out of the original
core.d.ts
library.
Roughly, yes. See src/lib/default.es5.d.ts
I see. Given this new approach, it might then change the suggestion I put forth to effectively become:
/// <reference lib="dom.support" />
Perhaps it's not the cleanest, but it would theoretically isolate ES3 and ES5 better, making further edits to those libraries be maintenance-only and help curb (or enable workarounds for) the odd conflicts that show up occasionally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I see what you are getting at. Perhaps the best breakdown would be:
- lib.es3.d.ts - ES3 only
- lib.es5.d.ts - ES5 only, though may need to delay several releases as node.d.ts depends on Promise/TypedArray as it exists today
- lib.es2015.promise.core.d.ts - Promise type information (without Promise constructor)
- lib.es2015.promise.d.ts - References es2015.promise.core, adds Promise constructor
- lib.es2015.typedarray.core.d.ts - TypedArray types (without TypedArray constructors)
- lib.es2015.typedarray.d.ts - References es2015.typedarray.core, adds TypedArray constructors
- lib.dom.d.ts - References es2015.promise.core and es2015.typedarray.core, contains all of dom.generated
The lib.dom.d.ts would have to pull in Promise and TypedArray as they are required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rbuckton That would certainly be a clean approach! To where would you suggest moving the Decorator
types? As far as JavaScript is concerned, these are still a proposal (perhaps even more of a reason to get them out of the EC3/EC5 libraries. Given that even in TypeScript they require the experimentalDecorators
compiler option, perhaps a library like the following would work:
- lib.experimental.decorator.d.ts - Decorator type information.
These could probably exist on their own, to be honest. They were initially brought into core
before it became es5.d.ts
and seem to have just stuck around. There appear to be no interdependencies with other types in either lib.d.ts
or lib.dom.d.ts
. They are used in TypeScript when the experimentalDecorators
option is set, but perhaps that setting can also imply lib=["experimental.decorator"]
?
Also, please resolve the current conflicts with master. |
@saschanaz this change will need to wait for #15780 to go in first. #15780 will split lib.d.ts into smaller components, so this will avoid some of the conditions you have for when es3.full would be used. |
IMHO this is an unnecessary breaking change. See discussion in #16132. |
@BurtHarris This PR just adds es3.d.ts and won't break anything. #16132 (and some part of the conversation here) is a different discussion. |
Any progress on this PR? |
Thanks for your contribution. This PR has not been updated in a while and cannot be automatically merged at the time being. For housekeeping purposes we are closing stale PRs. If you'd still like to continue working on this PR, please leave a message and one of the maintainers can reopen it. |
@saschanaz With respect to this:
It appears as though @rbuckton completed the work (though that specific issue was superseded by #23893). Is the work done in that merge enough to get this moving? |
Maybe a silly question but is it really necessary that the ES5+ type definitions be changed to extend the ES3 definitions? Seems like omitting that part would greatly simplify these code changes, unless it would break something down the line that I'm not aware of. (The other concern I can think of is that definitions shared between the ES3 and ES5 types could get out of sync.) |
Fixes #2410
Fixes #15978
Test failure should be fixed after ivogabe/gulp-typescript#510 is merged.Done