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
enumType{A,B}interfaceA{type: Type.A}interfaceB{type: Type.B}typeAorB={value: A}|{value: Bextra: {}}declarevaraOrB: AorBif(aOrB.value.type===Type.B){constval: B=aOrB.value// OKaOrB.extra// not OK because it's missing in { value: A } but value cannot be A}
Expected behavior:
The narrowing of aOrB.value to also narrow the type of aOrB.
Actual behavior:
aOrB.extra cannot be accessed because the compiler still believes it can be { value: A } even though value has already been proven to not be A.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
TypeScript Version: playground
Search Terms: narrowing
Code
Expected behavior:
The narrowing of
aOrB.value
to also narrow the type ofaOrB
.Actual behavior:
aOrB.extra
cannot be accessed because the compiler still believes it can be{ value: A }
even thoughvalue
has already been proven to not beA
.Playground Link: https://www.typescriptlang.org/play/index.html#src=enum%20Type%20%7B%0A%20%20A%2C%0A%20%20B%0A%7D%0A%0Ainterface%20A%20%7B%0A%20%20type%3A%20Type.A%0A%7D%0A%0Ainterface%20B%20%7B%0A%20%20type%3A%20Type.B%0A%7D%0A%0Atype%20AorB%20%3D%20%7B%0A%20%20value%3A%20A%0A%7D%20%7C%20%7B%0A%20%20value%3A%20B%0A%20%20extra%3A%20%7B%7D%0A%7D%0A%0Adeclare%20var%20aOrB%3A%20AorB%0A%0Aif%20(aOrB.value.type%20%3D%3D%3D%20Type.B)%20%7B%0A%20%20const%20val%3A%20B%20%3D%20aOrB.value%20%2F%2F%20OK%0A%20%20aOrB.extra%20%2F%2F%20not%20OK%20because%20it's%20missing%20in%20%7B%20value%3A%20A%20%7D%20but%20value%20cannot%20be%20A%0A%7D%0A
The text was updated successfully, but these errors were encountered: