Test that `typeof x === 'random' as string`: 1. Does not issue an error. 2. Does not narrow.
41 lines
795 B
Plaintext
41 lines
795 B
Plaintext
=== tests/cases/conformance/expressions/typeGuards/typeGuardEnums.ts ===
|
|
enum E {}
|
|
>E : E
|
|
|
|
enum V {}
|
|
>V : V
|
|
|
|
let x: number|string|E|V;
|
|
>x : string | number | E | V
|
|
>E : E
|
|
>V : V
|
|
|
|
if (typeof x === "number") {
|
|
>typeof x === "number" : boolean
|
|
>typeof x : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
|
|
>x : string | number | E | V
|
|
>"number" : "number"
|
|
|
|
x; // number|E|V
|
|
>x : number | E | V
|
|
}
|
|
else {
|
|
x; // string
|
|
>x : string
|
|
}
|
|
|
|
if (typeof x !== "number") {
|
|
>typeof x !== "number" : boolean
|
|
>typeof x : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
|
|
>x : string | number | E | V
|
|
>"number" : "number"
|
|
|
|
x; // string
|
|
>x : string
|
|
}
|
|
else {
|
|
x; // number|E|V
|
|
>x : number | E | V
|
|
}
|
|
|