=== tests/cases/compiler/typeVariableTypeGuards.ts ===
// Repro from #14091
interface Foo {
foo(): void
>foo : () => void
}
class A
> {
>A : A
constructor(public props: Readonly
) {}
>props : Readonly
doSomething() {
>doSomething : () => void
this.props.foo && this.props.foo()
>this.props.foo && this.props.foo() : void | undefined
>this.props.foo : P["foo"] | undefined
>this.props : Readonly
>this : this
>props : Readonly
>foo : P["foo"] | undefined
>this.props.foo() : void
>this.props.foo : () => void
>this.props : Readonly
>this : this
>props : Readonly
>foo : () => void
}
}
// Repro from #14415
interface Banana {
color: 'yellow';
>color : "yellow"
}
class Monkey {
>Monkey : Monkey
constructor(public a: T) {}
>a : T
render() {
>render : () => void
if (this.a) {
>this.a : T
>this : this
>a : T
this.a.color;
>this.a.color : "yellow"
>this.a : Banana
>this : this
>a : Banana
>color : "yellow"
}
}
}
interface BigBanana extends Banana {
}
class BigMonkey extends Monkey {
>BigMonkey : BigMonkey
>Monkey : Monkey
render() {
>render : () => void
if (this.a) {
>this.a : BigBanana
>this : this
>a : BigBanana
this.a.color;
>this.a.color : "yellow"
>this.a : BigBanana
>this : this
>a : BigBanana
>color : "yellow"
}
}
}
// Another repro
type Item = {
>Item : Item
(): string;
x: string;
>x : string
}
function f1(obj: T) {
>f1 : (obj: T) => void
>obj : T
if (obj) {
>obj : T
obj.x;
>obj.x : string
>obj : Item
>x : string
obj["x"];
>obj["x"] : string
>obj : Item
>"x" : "x"
obj();
>obj() : string
>obj : Item
}
}
function f2(obj: T | undefined) {
>f2 : (obj: T | undefined) => void
>obj : T | undefined
if (obj) {
>obj : T | undefined
obj.x;
>obj.x : string
>obj : Item
>x : string
obj["x"];
>obj["x"] : string
>obj : Item
>"x" : "x"
obj();
>obj() : string
>obj : Item
}
}
function f3(obj: T | null) {
>f3 : (obj: T | null) => void
>obj : T | null
>null : null
if (obj) {
>obj : T | null
obj.x;
>obj.x : string
>obj : Item
>x : string
obj["x"];
>obj["x"] : string
>obj : Item
>"x" : "x"
obj();
>obj() : string
>obj : Item
}
}
function f4(obj: T | undefined, x: number) {
>f4 : (obj: T | undefined, x: number) => void
>obj : T | undefined
>x : number
if (obj) {
>obj : T | undefined
obj[x].length;
>obj[x].length : number
>obj[x] : string
>obj : string[]
>x : number
>length : number
}
}
function f5(obj: T | undefined, key: K) {
>f5 : (obj: T | undefined, key: K) => void
>obj : T | undefined
>key : K
if (obj) {
>obj : T | undefined
obj[key];
>obj[key] : T[K]
>obj : T
>key : K
}
}