|
| 1 | +=== tests/cases/compiler/typeVariableTypeGuards.ts === |
| 2 | +// Repro from #14091 |
| 3 | + |
| 4 | +interface Foo { |
| 5 | +>Foo : Symbol(Foo, Decl(typeVariableTypeGuards.ts, 0, 0)) |
| 6 | + |
| 7 | + foo(): void |
| 8 | +>foo : Symbol(Foo.foo, Decl(typeVariableTypeGuards.ts, 2, 15)) |
| 9 | +} |
| 10 | + |
| 11 | +class A<P extends Partial<Foo>> { |
| 12 | +>A : Symbol(A, Decl(typeVariableTypeGuards.ts, 4, 1)) |
| 13 | +>P : Symbol(P, Decl(typeVariableTypeGuards.ts, 6, 8)) |
| 14 | +>Partial : Symbol(Partial, Decl(lib.d.ts, --, --)) |
| 15 | +>Foo : Symbol(Foo, Decl(typeVariableTypeGuards.ts, 0, 0)) |
| 16 | + |
| 17 | + props: Readonly<P> |
| 18 | +>props : Symbol(A.props, Decl(typeVariableTypeGuards.ts, 6, 33)) |
| 19 | +>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --)) |
| 20 | +>P : Symbol(P, Decl(typeVariableTypeGuards.ts, 6, 8)) |
| 21 | + |
| 22 | + doSomething() { |
| 23 | +>doSomething : Symbol(A.doSomething, Decl(typeVariableTypeGuards.ts, 7, 22)) |
| 24 | + |
| 25 | + this.props.foo && this.props.foo() |
| 26 | +>this.props.foo : Symbol(foo) |
| 27 | +>this.props : Symbol(A.props, Decl(typeVariableTypeGuards.ts, 6, 33)) |
| 28 | +>this : Symbol(A, Decl(typeVariableTypeGuards.ts, 4, 1)) |
| 29 | +>props : Symbol(A.props, Decl(typeVariableTypeGuards.ts, 6, 33)) |
| 30 | +>foo : Symbol(foo) |
| 31 | +>this.props.foo : Symbol(foo) |
| 32 | +>this.props : Symbol(A.props, Decl(typeVariableTypeGuards.ts, 6, 33)) |
| 33 | +>this : Symbol(A, Decl(typeVariableTypeGuards.ts, 4, 1)) |
| 34 | +>props : Symbol(A.props, Decl(typeVariableTypeGuards.ts, 6, 33)) |
| 35 | +>foo : Symbol(foo) |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +// Repro from #14415 |
| 40 | + |
| 41 | +interface Banana { |
| 42 | +>Banana : Symbol(Banana, Decl(typeVariableTypeGuards.ts, 11, 1)) |
| 43 | + |
| 44 | + color: 'yellow'; |
| 45 | +>color : Symbol(Banana.color, Decl(typeVariableTypeGuards.ts, 15, 18)) |
| 46 | +} |
| 47 | + |
| 48 | +class Monkey<T extends Banana | undefined> { |
| 49 | +>Monkey : Symbol(Monkey, Decl(typeVariableTypeGuards.ts, 17, 1)) |
| 50 | +>T : Symbol(T, Decl(typeVariableTypeGuards.ts, 19, 13)) |
| 51 | +>Banana : Symbol(Banana, Decl(typeVariableTypeGuards.ts, 11, 1)) |
| 52 | + |
| 53 | + a: T; |
| 54 | +>a : Symbol(Monkey.a, Decl(typeVariableTypeGuards.ts, 19, 44)) |
| 55 | +>T : Symbol(T, Decl(typeVariableTypeGuards.ts, 19, 13)) |
| 56 | + |
| 57 | + render() { |
| 58 | +>render : Symbol(Monkey.render, Decl(typeVariableTypeGuards.ts, 20, 9)) |
| 59 | + |
| 60 | + if (this.a) { |
| 61 | +>this.a : Symbol(Monkey.a, Decl(typeVariableTypeGuards.ts, 19, 44)) |
| 62 | +>this : Symbol(Monkey, Decl(typeVariableTypeGuards.ts, 17, 1)) |
| 63 | +>a : Symbol(Monkey.a, Decl(typeVariableTypeGuards.ts, 19, 44)) |
| 64 | + |
| 65 | + this.a.color; |
| 66 | +>this.a.color : Symbol(Banana.color, Decl(typeVariableTypeGuards.ts, 15, 18)) |
| 67 | +>this.a : Symbol(Monkey.a, Decl(typeVariableTypeGuards.ts, 19, 44)) |
| 68 | +>this : Symbol(Monkey, Decl(typeVariableTypeGuards.ts, 17, 1)) |
| 69 | +>a : Symbol(Monkey.a, Decl(typeVariableTypeGuards.ts, 19, 44)) |
| 70 | +>color : Symbol(Banana.color, Decl(typeVariableTypeGuards.ts, 15, 18)) |
| 71 | + } |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +interface BigBanana extends Banana { |
| 76 | +>BigBanana : Symbol(BigBanana, Decl(typeVariableTypeGuards.ts, 26, 1)) |
| 77 | +>Banana : Symbol(Banana, Decl(typeVariableTypeGuards.ts, 11, 1)) |
| 78 | +} |
| 79 | + |
| 80 | +class BigMonkey extends Monkey<BigBanana> { |
| 81 | +>BigMonkey : Symbol(BigMonkey, Decl(typeVariableTypeGuards.ts, 29, 1)) |
| 82 | +>Monkey : Symbol(Monkey, Decl(typeVariableTypeGuards.ts, 17, 1)) |
| 83 | +>BigBanana : Symbol(BigBanana, Decl(typeVariableTypeGuards.ts, 26, 1)) |
| 84 | + |
| 85 | + render() { |
| 86 | +>render : Symbol(BigMonkey.render, Decl(typeVariableTypeGuards.ts, 31, 43)) |
| 87 | + |
| 88 | + if (this.a) { |
| 89 | +>this.a : Symbol(Monkey.a, Decl(typeVariableTypeGuards.ts, 19, 44)) |
| 90 | +>this : Symbol(BigMonkey, Decl(typeVariableTypeGuards.ts, 29, 1)) |
| 91 | +>a : Symbol(Monkey.a, Decl(typeVariableTypeGuards.ts, 19, 44)) |
| 92 | + |
| 93 | + this.a.color; |
| 94 | +>this.a.color : Symbol(Banana.color, Decl(typeVariableTypeGuards.ts, 15, 18)) |
| 95 | +>this.a : Symbol(Monkey.a, Decl(typeVariableTypeGuards.ts, 19, 44)) |
| 96 | +>this : Symbol(BigMonkey, Decl(typeVariableTypeGuards.ts, 29, 1)) |
| 97 | +>a : Symbol(Monkey.a, Decl(typeVariableTypeGuards.ts, 19, 44)) |
| 98 | +>color : Symbol(Banana.color, Decl(typeVariableTypeGuards.ts, 15, 18)) |
| 99 | + } |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +// Another repro |
| 104 | + |
| 105 | +type Item = { |
| 106 | +>Item : Symbol(Item, Decl(typeVariableTypeGuards.ts, 37, 1)) |
| 107 | + |
| 108 | + (): string; |
| 109 | + x: string; |
| 110 | +>x : Symbol(x, Decl(typeVariableTypeGuards.ts, 42, 15)) |
| 111 | +} |
| 112 | + |
| 113 | +function f1<T extends Item | undefined>(obj: T) { |
| 114 | +>f1 : Symbol(f1, Decl(typeVariableTypeGuards.ts, 44, 1)) |
| 115 | +>T : Symbol(T, Decl(typeVariableTypeGuards.ts, 46, 12)) |
| 116 | +>Item : Symbol(Item, Decl(typeVariableTypeGuards.ts, 37, 1)) |
| 117 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 46, 40)) |
| 118 | +>T : Symbol(T, Decl(typeVariableTypeGuards.ts, 46, 12)) |
| 119 | + |
| 120 | + if (obj) { |
| 121 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 46, 40)) |
| 122 | + |
| 123 | + obj.x; |
| 124 | +>obj.x : Symbol(x, Decl(typeVariableTypeGuards.ts, 42, 15)) |
| 125 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 46, 40)) |
| 126 | +>x : Symbol(x, Decl(typeVariableTypeGuards.ts, 42, 15)) |
| 127 | + |
| 128 | + obj["x"]; |
| 129 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 46, 40)) |
| 130 | +>"x" : Symbol(x, Decl(typeVariableTypeGuards.ts, 42, 15)) |
| 131 | + |
| 132 | + obj(); |
| 133 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 46, 40)) |
| 134 | + } |
| 135 | +} |
| 136 | + |
| 137 | +function f2<T extends Item | undefined>(obj: T | undefined) { |
| 138 | +>f2 : Symbol(f2, Decl(typeVariableTypeGuards.ts, 52, 1)) |
| 139 | +>T : Symbol(T, Decl(typeVariableTypeGuards.ts, 54, 12)) |
| 140 | +>Item : Symbol(Item, Decl(typeVariableTypeGuards.ts, 37, 1)) |
| 141 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 54, 40)) |
| 142 | +>T : Symbol(T, Decl(typeVariableTypeGuards.ts, 54, 12)) |
| 143 | + |
| 144 | + if (obj) { |
| 145 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 54, 40)) |
| 146 | + |
| 147 | + obj.x; |
| 148 | +>obj.x : Symbol(x, Decl(typeVariableTypeGuards.ts, 42, 15)) |
| 149 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 54, 40)) |
| 150 | +>x : Symbol(x, Decl(typeVariableTypeGuards.ts, 42, 15)) |
| 151 | + |
| 152 | + obj["x"]; |
| 153 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 54, 40)) |
| 154 | +>"x" : Symbol(x, Decl(typeVariableTypeGuards.ts, 42, 15)) |
| 155 | + |
| 156 | + obj(); |
| 157 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 54, 40)) |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +function f3<T extends Item | undefined>(obj: T | null) { |
| 162 | +>f3 : Symbol(f3, Decl(typeVariableTypeGuards.ts, 60, 1)) |
| 163 | +>T : Symbol(T, Decl(typeVariableTypeGuards.ts, 62, 12)) |
| 164 | +>Item : Symbol(Item, Decl(typeVariableTypeGuards.ts, 37, 1)) |
| 165 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 62, 40)) |
| 166 | +>T : Symbol(T, Decl(typeVariableTypeGuards.ts, 62, 12)) |
| 167 | + |
| 168 | + if (obj) { |
| 169 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 62, 40)) |
| 170 | + |
| 171 | + obj.x; |
| 172 | +>obj.x : Symbol(x, Decl(typeVariableTypeGuards.ts, 42, 15)) |
| 173 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 62, 40)) |
| 174 | +>x : Symbol(x, Decl(typeVariableTypeGuards.ts, 42, 15)) |
| 175 | + |
| 176 | + obj["x"]; |
| 177 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 62, 40)) |
| 178 | +>"x" : Symbol(x, Decl(typeVariableTypeGuards.ts, 42, 15)) |
| 179 | + |
| 180 | + obj(); |
| 181 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 62, 40)) |
| 182 | + } |
| 183 | +} |
| 184 | + |
| 185 | +function f4<T extends string[] | undefined>(obj: T | undefined, x: number) { |
| 186 | +>f4 : Symbol(f4, Decl(typeVariableTypeGuards.ts, 68, 1)) |
| 187 | +>T : Symbol(T, Decl(typeVariableTypeGuards.ts, 70, 12)) |
| 188 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 70, 44)) |
| 189 | +>T : Symbol(T, Decl(typeVariableTypeGuards.ts, 70, 12)) |
| 190 | +>x : Symbol(x, Decl(typeVariableTypeGuards.ts, 70, 63)) |
| 191 | + |
| 192 | + if (obj) { |
| 193 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 70, 44)) |
| 194 | + |
| 195 | + obj[x].length; |
| 196 | +>obj[x].length : Symbol(String.length, Decl(lib.d.ts, --, --)) |
| 197 | +>obj : Symbol(obj, Decl(typeVariableTypeGuards.ts, 70, 44)) |
| 198 | +>x : Symbol(x, Decl(typeVariableTypeGuards.ts, 70, 63)) |
| 199 | +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) |
| 200 | + } |
| 201 | +} |
| 202 | + |
0 commit comments