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