Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Set and Map don't infer own types (regression) #21112

Closed
falsandtru opened this issue Jan 10, 2018 · 2 comments
Closed

Set and Map don't infer own types (regression) #21112

falsandtru opened this issue Jan 10, 2018 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@falsandtru
Copy link
Contributor

#20606 should be reverted for now.

TypeScript Version: master

Code

new Set([]);

Expected behavior:

Set<never>

Actual behavior:

Set<never | ReadonlyArray<never> | undefined>

Related:

@ahejlsberg
Copy link
Member

This actually looks to be a regression caused by #19745. A simple repro:

declare function foo<T>(a?: ReadonlyArray<T>): T;
let x = foo([]);  // never | ReadonlyArray<never> | undefined

The issue is that when inferring from Array<T> to ReadonlyArray<T> we structurally relate the types, which produces a number of secondary inferences. Usually these secondary inferences are suppressed by a higher priority inference of never, but with #19745 that doesn't happen (because inferences from an implicit never[] are given even lower priority).

@ahejlsberg ahejlsberg self-assigned this Jan 10, 2018
@ahejlsberg ahejlsberg added the Bug A bug in TypeScript label Jan 10, 2018
@ahejlsberg ahejlsberg added this to the TypeScript 2.7 milestone Jan 10, 2018
@falsandtru
Copy link
Contributor Author

This regression, it happens with common cases and makes a large impact, shouldn't be released with the next stable version. Should be fixed by no later than the next releasing.

@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Jan 12, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants