|
| 1 | +//// [tests/cases/compiler/narrowBySwitchDiscriminantUndefinedCase1.ts] //// |
| 2 | + |
| 3 | +=== narrowBySwitchDiscriminantUndefinedCase1.ts === |
| 4 | +// https://github.com/microsoft/TypeScript/issues/57999 |
| 5 | + |
| 6 | +interface A { |
| 7 | +>A : Symbol(A, Decl(narrowBySwitchDiscriminantUndefinedCase1.ts, 0, 0)) |
| 8 | + |
| 9 | + optionalProp?: "hello"; |
| 10 | +>optionalProp : Symbol(A.optionalProp, Decl(narrowBySwitchDiscriminantUndefinedCase1.ts, 2, 13)) |
| 11 | +} |
| 12 | + |
| 13 | +function func(arg: A) { |
| 14 | +>func : Symbol(func, Decl(narrowBySwitchDiscriminantUndefinedCase1.ts, 4, 1)) |
| 15 | +>arg : Symbol(arg, Decl(narrowBySwitchDiscriminantUndefinedCase1.ts, 6, 14)) |
| 16 | +>A : Symbol(A, Decl(narrowBySwitchDiscriminantUndefinedCase1.ts, 0, 0)) |
| 17 | + |
| 18 | + const { optionalProp } = arg; |
| 19 | +>optionalProp : Symbol(optionalProp, Decl(narrowBySwitchDiscriminantUndefinedCase1.ts, 7, 9)) |
| 20 | +>arg : Symbol(arg, Decl(narrowBySwitchDiscriminantUndefinedCase1.ts, 6, 14)) |
| 21 | + |
| 22 | + switch (optionalProp) { |
| 23 | +>optionalProp : Symbol(optionalProp, Decl(narrowBySwitchDiscriminantUndefinedCase1.ts, 7, 9)) |
| 24 | + |
| 25 | + case undefined: |
| 26 | +>undefined : Symbol(undefined) |
| 27 | + |
| 28 | + return undefined; |
| 29 | +>undefined : Symbol(undefined) |
| 30 | + |
| 31 | + case "hello": |
| 32 | + return "hello"; |
| 33 | + default: |
| 34 | + assertUnreachable(optionalProp); |
| 35 | +>assertUnreachable : Symbol(assertUnreachable, Decl(narrowBySwitchDiscriminantUndefinedCase1.ts, 30, 1)) |
| 36 | +>optionalProp : Symbol(optionalProp, Decl(narrowBySwitchDiscriminantUndefinedCase1.ts, 7, 9)) |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +function func2() { |
| 41 | +>func2 : Symbol(func2, Decl(narrowBySwitchDiscriminantUndefinedCase1.ts, 17, 1)) |
| 42 | + |
| 43 | + const optionalProp = ["hello" as const][Math.random()]; |
| 44 | +>optionalProp : Symbol(optionalProp, Decl(narrowBySwitchDiscriminantUndefinedCase1.ts, 20, 7)) |
| 45 | +>const : Symbol(const) |
| 46 | +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) |
| 47 | +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) |
| 48 | +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) |
| 49 | + |
| 50 | + switch (optionalProp) { |
| 51 | +>optionalProp : Symbol(optionalProp, Decl(narrowBySwitchDiscriminantUndefinedCase1.ts, 20, 7)) |
| 52 | + |
| 53 | + case undefined: |
| 54 | +>undefined : Symbol(undefined) |
| 55 | + |
| 56 | + return undefined; |
| 57 | +>undefined : Symbol(undefined) |
| 58 | + |
| 59 | + case "hello": |
| 60 | + return "hello"; |
| 61 | + default: |
| 62 | + assertUnreachable(optionalProp); |
| 63 | +>assertUnreachable : Symbol(assertUnreachable, Decl(narrowBySwitchDiscriminantUndefinedCase1.ts, 30, 1)) |
| 64 | +>optionalProp : Symbol(optionalProp, Decl(narrowBySwitchDiscriminantUndefinedCase1.ts, 20, 7)) |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +function assertUnreachable(_: never): never { |
| 69 | +>assertUnreachable : Symbol(assertUnreachable, Decl(narrowBySwitchDiscriminantUndefinedCase1.ts, 30, 1)) |
| 70 | +>_ : Symbol(_, Decl(narrowBySwitchDiscriminantUndefinedCase1.ts, 32, 27)) |
| 71 | + |
| 72 | + throw new Error("Unreachable path taken"); |
| 73 | +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) |
| 74 | +} |
| 75 | + |
0 commit comments