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
|
=== tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts ===
interface IndexedWithThis {
>IndexedWithThis : IndexedWithThis
// this is a workaround for React
init?: (this: this) => void;
>init : (this: this) => void
>this : this
willDestroy?: (this: any) => void;
>willDestroy : (this: any) => void
>this : any
[propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any);
>propName : string
>null : null
>this : any
>args : any[]
}
interface IndexedWithoutThis {
>IndexedWithoutThis : IndexedWithoutThis
// this is what React would like to write (and what they write today)
init?: () => void;
>init : () => void
willDestroy?: () => void;
>willDestroy : () => void
[propName: string]: any;
>propName : string
}
interface SimpleInterface {
>SimpleInterface : SimpleInterface
foo(n: string);
>foo : (n: string) => any
>n : string
bar(): number;
>bar : () => number
}
declare function extend1(args: IndexedWithThis): void;
>extend1 : (args: IndexedWithThis) => void
>args : IndexedWithThis
>IndexedWithThis : IndexedWithThis
declare function extend2(args: IndexedWithoutThis): void;
>extend2 : (args: IndexedWithoutThis) => void
>args : IndexedWithoutThis
>IndexedWithoutThis : IndexedWithoutThis
declare function simple(arg: SimpleInterface): void;
>simple : (arg: SimpleInterface) => void
>arg : SimpleInterface
>SimpleInterface : SimpleInterface
extend1({
>extend1({ init() { this // this: IndexedWithThis because of contextual typing. // this.mine this.willDestroy }, mine: 12, foo() { this.url; // this: any because 'foo' matches the string indexer this.willDestroy; }}) : void
>extend1 : (args: IndexedWithThis) => void
>{ init() { this // this: IndexedWithThis because of contextual typing. // this.mine this.willDestroy }, mine: 12, foo() { this.url; // this: any because 'foo' matches the string indexer this.willDestroy; }} : { init(this: IndexedWithThis): void; mine: 12; foo(this: any): void; }
init() {
>init : (this: IndexedWithThis) => void
this // this: IndexedWithThis because of contextual typing.
>this : IndexedWithThis
// this.mine
this.willDestroy
>this.willDestroy : (this: any) => void
>this : IndexedWithThis
>willDestroy : (this: any) => void
},
mine: 12,
>mine : number
>12 : 12
foo() {
>foo : (this: any) => void
this.url; // this: any because 'foo' matches the string indexer
>this.url : any
>this : any
>url : any
this.willDestroy;
>this.willDestroy : any
>this : any
>willDestroy : any
}
});
extend2({
>extend2({ init() { this // this: any because the contextual signature of init doesn't specify this' type this.mine this.willDestroy }, mine: 13, foo() { this // this: any because of the string indexer this.mine this.willDestroy }}) : void
>extend2 : (args: IndexedWithoutThis) => void
>{ init() { this // this: any because the contextual signature of init doesn't specify this' type this.mine this.willDestroy }, mine: 13, foo() { this // this: any because of the string indexer this.mine this.willDestroy }} : { init(): void; mine: number; foo(): void; }
init() {
>init : () => void
this // this: any because the contextual signature of init doesn't specify this' type
>this : any
this.mine
>this.mine : any
>this : any
>mine : any
this.willDestroy
>this.willDestroy : any
>this : any
>willDestroy : any
},
mine: 13,
>mine : number
>13 : 13
foo() {
>foo : () => void
this // this: any because of the string indexer
>this : any
this.mine
>this.mine : any
>this : any
>mine : any
this.willDestroy
>this.willDestroy : any
>this : any
>willDestroy : any
}
});
simple({
>simple({ foo(n) { return n.length + this.bar(); }, bar() { return 14; }}) : void
>simple : (arg: SimpleInterface) => void
>{ foo(n) { return n.length + this.bar(); }, bar() { return 14; }} : { foo(n: string): any; bar(): number; }
foo(n) {
>foo : (n: string) => any
>n : string
return n.length + this.bar();
>n.length + this.bar() : any
>n.length : number
>n : string
>length : number
>this.bar() : any
>this.bar : any
>this : any
>bar : any
},
bar() {
>bar : () => number
return 14;
>14 : 14
}
})
|