-
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
Conflicting definitions for Set constructor causes unexpected default generic in TS 3.5 #31990
Comments
@weswigham I think this might be unintended fallout of your default type parameter constraints change, maybe? #30637 I think the two constructors should at least be consistent, but I'm not sure which is preferred, probably the |
Yeah, I'm not sure why we even have a version of the constructor that defaults to |
let arr1 = new Array(10); // any[] - bad
let arr2 = new Array<number>(10); // number[] - good |
@DanielRosenwasser do we want to change our behavior here? I think we last looked at it some time around #25374 |
Perhaps related, I notice in 3.4->3.5, SetConstructor changed from
to
So perhaps that is changing which overload is selected when. |
Yeah, it's unsafe, but it would be incredibly annoying to break people. This sort of comes back to the "I want this to be an 'implicit any' for the |
I guess it can’t really be |
Just to restate, what I am concerned about here is whether "new Set()" is supposed to give you a I believe the intention was for 3.5 change it to |
Circling back on this -- I think maybe I failed to communicate the bug here. In practice, TS3.4 => TS3.5 changed what But the actual bug here is that I think you didn't change the definition of Set! It still says |
TypeScript Version: 3.4.5 vs versions after 3.5
Search Terms: set constructor setconstructor unknown
Code
Expected behavior:
In TS 3.4: we expect the default chosen param to give us a
Set<{}>
.In TS 3.5: we expect a
Set<unknown>
.That change was an intended change in TS 3.5.
Or, if Set has a default generic arg, I expect the same default chosen in 3.4 and 3.5.
Actual behavior:
In TS 3.4, this actually was a
Set<any>
!It appears there are multiple overloads of the Set constructor.
lib.es2015.collection.d.ts says:
while lib.es2105.iterable.d.ts says:
Note that one has
T = any
and the other doesn't.So somehow TS 3.4 vs TS 3.5 decided to change whether to obey the
any
default, I think?The text was updated successfully, but these errors were encountered: