Closed
Description
assuming my understanding it right: an extended union is a subset (subtype) of the original union
declare function never(never: never): never;
type X = 'A' | 'B' | 'C';
void function fn<Y extends X>(y: Y): Y {
switch (y) {
case 'A': return y;
case 'B': return y;
case 'C': return y;
default: return never(y); // <-- y expected to be never, actual Y
}
}
same problem with objects
type X = { k: 'A' } | { k: 'B' } | { k: 'C' };
void function fn<Y extends X>(y: Y): Y {
switch (y.k) {
case 'A': return y;
case 'B': return y;
case 'C': return y;
default: return never(y); // <-- y expected to be never, actual Y
}
}
Activity
masaeedu commentedon Nov 30, 2017
Nvm earlier comment, misunderstood what you meant by "extended". The weird part here is
y
is being inferred asnever
in each of the'A'
,'B'
and'C'
cases.mhegazy commentedon Dec 2, 2017
Generics that are constrained to literal types are not treated like literals at the moment. generics have a more conservative behavior when narrowing in general since the actual type is not known, but generics with literal constraints should be behave like a union of literals.
sandersn commentedon Dec 4, 2017
In the first example,
y
isnever
in the case A/B/C branches. This, too , seems wrong.RyanCavanaugh commentedon Jan 30, 2018
This is indeed super wrong
24 remaining items