You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Exhaustive type checking not working when class field to match on is a union #40160
classEither<T>{publicstaticLeft<T>(value: T): Either<T>{returnnewEither('left',value);}publicstaticRight<T>(value: T): Either<T>{returnnewEither('right',value);}privateconstructor(publicreadonlykind: 'left'|'right',publicreadonlyvalue: T){}}functiondoSomething(): string{conste=Either.Left('foo');// e.kind: 'left' | 'right';switch(e.kind){case'left':
returne.value;case'right':
returne.value;// case 'foo': as expected, this doesn't work// break;default:
const_exhaustiveCheck: never=e;// even though we've matched against all the possible cases of `kind`, compiler still complains herethrownewError("How did we get here?");}}
Activity
jack-williams commentedon Aug 21, 2020
Duplicate of #38963. The narrowing of a property is not propagated back to the parent object unless the parent is a discriminated union type.
You can use the property as evidence of unreachability:
In theory being able to conjure any value of type
neveris sufficient to show that the statement is unreachable.typescript-bot commentedon Aug 23, 2020
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.