TypeScript Version: master
Code
new Set([]);
Expected behavior:
Set<never>
Actual behavior:
Set<never | ReadonlyArray<never> | undefined>
Related:
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).
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.
Most helpful comment
This actually looks to be a regression caused by #19745. A simple repro:
The issue is that when inferring from
Array<T>toReadonlyArray<T>we structurally relate the types, which produces a number of secondary inferences. Usually these secondary inferences are suppressed by a higher priority inference ofnever, but with #19745 that doesn't happen (because inferences from an implicitnever[]are given even lower priority).