|
| 1 | +=== tests/cases/compiler/emptyAnonymousObjectNarrowing.ts === |
| 2 | +declare let nonNull: {}; |
| 3 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 4 | + |
| 5 | +if (nonNull === "foo") { |
| 6 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 7 | + |
| 8 | + nonNull; |
| 9 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 10 | +} |
| 11 | +else { |
| 12 | + nonNull; |
| 13 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 14 | +} |
| 15 | + |
| 16 | +declare let obj: { a: string }; |
| 17 | +>obj : Symbol(obj, Decl(emptyAnonymousObjectNarrowing.ts, 8, 11)) |
| 18 | +>a : Symbol(a, Decl(emptyAnonymousObjectNarrowing.ts, 8, 18)) |
| 19 | + |
| 20 | +if (nonNull === obj) { |
| 21 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 22 | +>obj : Symbol(obj, Decl(emptyAnonymousObjectNarrowing.ts, 8, 11)) |
| 23 | + |
| 24 | + nonNull; |
| 25 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 26 | +} |
| 27 | +else { |
| 28 | + nonNull; |
| 29 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 30 | +} |
| 31 | + |
| 32 | +function f1<T>(x: T) { |
| 33 | +>f1 : Symbol(f1, Decl(emptyAnonymousObjectNarrowing.ts, 14, 1)) |
| 34 | +>T : Symbol(T, Decl(emptyAnonymousObjectNarrowing.ts, 16, 12)) |
| 35 | +>x : Symbol(x, Decl(emptyAnonymousObjectNarrowing.ts, 16, 15)) |
| 36 | +>T : Symbol(T, Decl(emptyAnonymousObjectNarrowing.ts, 16, 12)) |
| 37 | + |
| 38 | + if (nonNull === x) { |
| 39 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 40 | +>x : Symbol(x, Decl(emptyAnonymousObjectNarrowing.ts, 16, 15)) |
| 41 | + |
| 42 | + nonNull; |
| 43 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 44 | + } |
| 45 | + else { |
| 46 | + nonNull; |
| 47 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +function f2<T extends object>(x: T) { |
| 52 | +>f2 : Symbol(f2, Decl(emptyAnonymousObjectNarrowing.ts, 23, 1)) |
| 53 | +>T : Symbol(T, Decl(emptyAnonymousObjectNarrowing.ts, 25, 12)) |
| 54 | +>x : Symbol(x, Decl(emptyAnonymousObjectNarrowing.ts, 25, 30)) |
| 55 | +>T : Symbol(T, Decl(emptyAnonymousObjectNarrowing.ts, 25, 12)) |
| 56 | + |
| 57 | + if (nonNull === x) { |
| 58 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 59 | +>x : Symbol(x, Decl(emptyAnonymousObjectNarrowing.ts, 25, 30)) |
| 60 | + |
| 61 | + nonNull; |
| 62 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 63 | + } |
| 64 | + else { |
| 65 | + nonNull; |
| 66 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +declare let union: "xyz" | { a: string } | undefined; |
| 71 | +>union : Symbol(union, Decl(emptyAnonymousObjectNarrowing.ts, 34, 11)) |
| 72 | +>a : Symbol(a, Decl(emptyAnonymousObjectNarrowing.ts, 34, 28)) |
| 73 | + |
| 74 | +if (nonNull === union) { |
| 75 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 76 | +>union : Symbol(union, Decl(emptyAnonymousObjectNarrowing.ts, 34, 11)) |
| 77 | + |
| 78 | + nonNull; |
| 79 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 80 | +} |
| 81 | +else { |
| 82 | + nonNull; |
| 83 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 84 | +} |
| 85 | + |
| 86 | +if (nonNull === undefined) { |
| 87 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 88 | +>undefined : Symbol(undefined) |
| 89 | + |
| 90 | + nonNull; |
| 91 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 92 | +} |
| 93 | +else { |
| 94 | + nonNull; |
| 95 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 96 | +} |
| 97 | + |
| 98 | +if (nonNull === null) { |
| 99 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 100 | + |
| 101 | + nonNull; |
| 102 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 103 | +} |
| 104 | +else { |
| 105 | + nonNull; |
| 106 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 107 | +} |
| 108 | + |
| 109 | +if (nonNull == undefined) { |
| 110 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 111 | +>undefined : Symbol(undefined) |
| 112 | + |
| 113 | + nonNull; |
| 114 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 115 | +} |
| 116 | +else { |
| 117 | + nonNull; |
| 118 | +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) |
| 119 | +} |
| 120 | + |
| 121 | +// Repro from #50567 |
| 122 | +const foo = (value: unknown): string => { |
| 123 | +>foo : Symbol(foo, Decl(emptyAnonymousObjectNarrowing.ts, 64, 5)) |
| 124 | +>value : Symbol(value, Decl(emptyAnonymousObjectNarrowing.ts, 64, 13)) |
| 125 | + |
| 126 | + if (!value) { |
| 127 | +>value : Symbol(value, Decl(emptyAnonymousObjectNarrowing.ts, 64, 13)) |
| 128 | + |
| 129 | + return 'foo'; |
| 130 | + } |
| 131 | + if (value === 'xyz') { |
| 132 | +>value : Symbol(value, Decl(emptyAnonymousObjectNarrowing.ts, 64, 13)) |
| 133 | + |
| 134 | + return value; // Type '{}' is not assignable to type 'string'. |
| 135 | +>value : Symbol(value, Decl(emptyAnonymousObjectNarrowing.ts, 64, 13)) |
| 136 | + } |
| 137 | + return ''; |
| 138 | +}; |
| 139 | + |
0 commit comments