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
constisSomeDiscriminatedUnion=(value: unknown): value is {type: "bar",lol: string}|{type: "baz",omg: string}=>truefunctiontest(value: unknown): string{if(isSomeDiscriminatedUnion(value)){if(value.type==="bar"){// ERROR! type narrowing didn't happen. value is still of type// { type: "bar", lol: string } | { type: "baz", omg: string }returnvalue.lol}// ERROR! type narrowing also didn't happen herereturnvalue.omg}return""}
Expected behavior:
Discriminated unions should be able to have their types narrowed after being identified by a type guard.
Actual behavior:
Discriminated unions do not have their types narrowed after being identified by a type guard.
TypeScript Version: 3.7-Beta
Search Terms:
type guard discriminated union
Code
Expected behavior:
Discriminated unions should be able to have their types narrowed after being identified by a type guard.
Actual behavior:
Discriminated unions do not have their types narrowed after being identified by a type guard.
Playground Link:
https://www.typescriptlang.org/play/index.html?ts=3.7-Beta#code/MYewdgzgLgBAlhAyiAtgUwCIOAJziuMAQyjQBMBVMOcGAXhgAoA3IgGwFc0AuGDsANZgQAdzABKXq05p4EGAG8YUAJ4AHHjABEAIyI4tAGhhsQbXtDxgA5jAC+MAD6Ll6zbqIAvIzFTWLUFa2DnQAfMo4XACwAFCxAGb8wFA0YMpo0CzsXLz8QqISAUGKsTDw8UwIyOhYELj4hCTkVKlZMuLiJTFlZXAVbVwAdKoa9HQMHgadCqU9ZQD08zAAKm4wxDg4ooS2EAAWIBxsZDB7RGoaYIMw0lww+4fHMDqyIBUjaLNziy4fvJM+Uzme6BHb2L49HBoKAcHBpW5oQZAiF2CE-VajDZbERgh5HE5nC5oK43bKyPFPF6+d5uNFLJR-bR6bzGPxFMGo7qQ6Gw+FkwZ+WacspQmFw7RaWKcoA
Related Issues:
The text was updated successfully, but these errors were encountered: