|
1 | 1 | === tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts ===
|
2 |
| -interface Arguments { |
3 |
| ->Arguments : Symbol(Arguments, Decl(thisTypeInFunctions2.ts, 0, 0)) |
| 2 | +interface IndexedWithThis { |
| 3 | +>IndexedWithThis : Symbol(IndexedWithThis, Decl(thisTypeInFunctions2.ts, 0, 0)) |
4 | 4 |
|
5 |
| - init?: (this: void) => void; |
6 |
| ->init : Symbol(Arguments.init, Decl(thisTypeInFunctions2.ts, 0, 21)) |
7 |
| ->this : Symbol(this, Decl(thisTypeInFunctions2.ts, 1, 12)) |
| 5 | + // this is a workaround for React |
| 6 | + init?: (this: this) => void; |
| 7 | +>init : Symbol(IndexedWithThis.init, Decl(thisTypeInFunctions2.ts, 0, 27)) |
| 8 | +>this : Symbol(this, Decl(thisTypeInFunctions2.ts, 2, 12)) |
8 | 9 |
|
9 | 10 | willDestroy?: (this: any) => void;
|
10 |
| ->willDestroy : Symbol(Arguments.willDestroy, Decl(thisTypeInFunctions2.ts, 1, 32)) |
11 |
| ->this : Symbol(this, Decl(thisTypeInFunctions2.ts, 2, 19)) |
| 11 | +>willDestroy : Symbol(IndexedWithThis.willDestroy, Decl(thisTypeInFunctions2.ts, 2, 32)) |
| 12 | +>this : Symbol(this, Decl(thisTypeInFunctions2.ts, 3, 19)) |
12 | 13 |
|
13 | 14 | [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any);
|
14 |
| ->propName : Symbol(propName, Decl(thisTypeInFunctions2.ts, 3, 5)) |
15 |
| ->this : Symbol(this, Decl(thisTypeInFunctions2.ts, 3, 87)) |
16 |
| ->args : Symbol(args, Decl(thisTypeInFunctions2.ts, 3, 97)) |
| 15 | +>propName : Symbol(propName, Decl(thisTypeInFunctions2.ts, 4, 5)) |
| 16 | +>this : Symbol(this, Decl(thisTypeInFunctions2.ts, 4, 87)) |
| 17 | +>args : Symbol(args, Decl(thisTypeInFunctions2.ts, 4, 97)) |
17 | 18 | }
|
18 |
| -declare function extend(arguments: Arguments): void; |
19 |
| ->extend : Symbol(extend, Decl(thisTypeInFunctions2.ts, 4, 1)) |
20 |
| ->arguments : Symbol(arguments, Decl(thisTypeInFunctions2.ts, 5, 24)) |
21 |
| ->Arguments : Symbol(Arguments, Decl(thisTypeInFunctions2.ts, 0, 0)) |
| 19 | +interface IndexedWithoutThis { |
| 20 | +>IndexedWithoutThis : Symbol(IndexedWithoutThis, Decl(thisTypeInFunctions2.ts, 5, 1)) |
22 | 21 |
|
23 |
| -class Mixin { |
24 |
| ->Mixin : Symbol(Mixin, Decl(thisTypeInFunctions2.ts, 5, 52)) |
| 22 | + // this is what React would like to write (and what they write today) |
| 23 | + init?: () => void; |
| 24 | +>init : Symbol(IndexedWithoutThis.init, Decl(thisTypeInFunctions2.ts, 6, 30)) |
25 | 25 |
|
26 |
| - stuff: number; |
27 |
| ->stuff : Symbol(Mixin.stuff, Decl(thisTypeInFunctions2.ts, 6, 13)) |
| 26 | + willDestroy?: () => void; |
| 27 | +>willDestroy : Symbol(IndexedWithoutThis.willDestroy, Decl(thisTypeInFunctions2.ts, 8, 22)) |
| 28 | + |
| 29 | + [propName: string]: any; |
| 30 | +>propName : Symbol(propName, Decl(thisTypeInFunctions2.ts, 10, 5)) |
| 31 | +} |
| 32 | +interface SimpleInterface { |
| 33 | +>SimpleInterface : Symbol(SimpleInterface, Decl(thisTypeInFunctions2.ts, 11, 1)) |
| 34 | + |
| 35 | + foo(n: string); |
| 36 | +>foo : Symbol(SimpleInterface.foo, Decl(thisTypeInFunctions2.ts, 12, 27)) |
| 37 | +>n : Symbol(n, Decl(thisTypeInFunctions2.ts, 13, 8)) |
| 38 | + |
| 39 | + bar(): number; |
| 40 | +>bar : Symbol(SimpleInterface.bar, Decl(thisTypeInFunctions2.ts, 13, 19)) |
28 | 41 | }
|
| 42 | +declare function extend1(args: IndexedWithThis): void; |
| 43 | +>extend1 : Symbol(extend1, Decl(thisTypeInFunctions2.ts, 15, 1)) |
| 44 | +>args : Symbol(args, Decl(thisTypeInFunctions2.ts, 16, 25)) |
| 45 | +>IndexedWithThis : Symbol(IndexedWithThis, Decl(thisTypeInFunctions2.ts, 0, 0)) |
29 | 46 |
|
30 |
| -extend({ |
31 |
| ->extend : Symbol(extend, Decl(thisTypeInFunctions2.ts, 4, 1)) |
| 47 | +declare function extend2(args: IndexedWithoutThis): void; |
| 48 | +>extend2 : Symbol(extend2, Decl(thisTypeInFunctions2.ts, 16, 54)) |
| 49 | +>args : Symbol(args, Decl(thisTypeInFunctions2.ts, 17, 25)) |
| 50 | +>IndexedWithoutThis : Symbol(IndexedWithoutThis, Decl(thisTypeInFunctions2.ts, 5, 1)) |
| 51 | + |
| 52 | +declare function simple(arg: SimpleInterface): void; |
| 53 | +>simple : Symbol(simple, Decl(thisTypeInFunctions2.ts, 17, 57)) |
| 54 | +>arg : Symbol(arg, Decl(thisTypeInFunctions2.ts, 18, 24)) |
| 55 | +>SimpleInterface : Symbol(SimpleInterface, Decl(thisTypeInFunctions2.ts, 11, 1)) |
| 56 | + |
| 57 | +extend1({ |
| 58 | +>extend1 : Symbol(extend1, Decl(thisTypeInFunctions2.ts, 15, 1)) |
32 | 59 |
|
33 | 60 | init() {
|
34 |
| ->init : Symbol(init, Decl(thisTypeInFunctions2.ts, 10, 8)) |
| 61 | +>init : Symbol(init, Decl(thisTypeInFunctions2.ts, 20, 9)) |
| 62 | + |
| 63 | + this // this: IndexedWithThis because of contextual typing. |
| 64 | +>this : Symbol(IndexedWithThis, Decl(thisTypeInFunctions2.ts, 0, 0)) |
| 65 | + |
| 66 | + // this.mine |
| 67 | + this.willDestroy |
| 68 | +>this.willDestroy : Symbol(IndexedWithThis.willDestroy, Decl(thisTypeInFunctions2.ts, 2, 32)) |
| 69 | +>this : Symbol(IndexedWithThis, Decl(thisTypeInFunctions2.ts, 0, 0)) |
| 70 | +>willDestroy : Symbol(IndexedWithThis.willDestroy, Decl(thisTypeInFunctions2.ts, 2, 32)) |
35 | 71 |
|
36 |
| - this |
37 | 72 | },
|
38 | 73 | mine: 12,
|
39 |
| ->mine : Symbol(mine, Decl(thisTypeInFunctions2.ts, 13, 6)) |
| 74 | +>mine : Symbol(mine, Decl(thisTypeInFunctions2.ts, 25, 6)) |
40 | 75 |
|
41 |
| - bar() { |
42 |
| ->bar : Symbol(bar, Decl(thisTypeInFunctions2.ts, 14, 13)) |
| 76 | + foo() { |
| 77 | +>foo : Symbol(foo, Decl(thisTypeInFunctions2.ts, 26, 13)) |
| 78 | + |
| 79 | + this.url; // this: any because 'foo' matches the string indexer |
| 80 | + this.willDestroy; |
| 81 | + } |
| 82 | +}); |
| 83 | +extend2({ |
| 84 | +>extend2 : Symbol(extend2, Decl(thisTypeInFunctions2.ts, 16, 54)) |
43 | 85 |
|
44 |
| - this.init(); |
| 86 | + init() { |
| 87 | +>init : Symbol(init, Decl(thisTypeInFunctions2.ts, 32, 9)) |
| 88 | + |
| 89 | + this // this: any because the contextual signature of init doesn't specify this' type |
| 90 | + this.mine |
| 91 | + this.willDestroy |
45 | 92 | },
|
| 93 | + mine: 13, |
| 94 | +>mine : Symbol(mine, Decl(thisTypeInFunctions2.ts, 37, 6)) |
| 95 | + |
46 | 96 | foo() {
|
47 |
| ->foo : Symbol(foo, Decl(thisTypeInFunctions2.ts, 17, 6)) |
| 97 | +>foo : Symbol(foo, Decl(thisTypeInFunctions2.ts, 38, 13)) |
48 | 98 |
|
49 |
| - this.bar; |
50 |
| - this.url |
51 |
| - this.handler() |
52 |
| - this.baz |
| 99 | + this // this: any because of the string indexer |
| 100 | + this.mine |
53 | 101 | this.willDestroy
|
54 | 102 | }
|
| 103 | +}); |
| 104 | + |
| 105 | +simple({ |
| 106 | +>simple : Symbol(simple, Decl(thisTypeInFunctions2.ts, 17, 57)) |
| 107 | + |
| 108 | + foo(n) { |
| 109 | +>foo : Symbol(foo, Decl(thisTypeInFunctions2.ts, 46, 8)) |
| 110 | +>n : Symbol(n, Decl(thisTypeInFunctions2.ts, 47, 8)) |
| 111 | + |
| 112 | + return n.length + this.bar(); |
| 113 | +>n.length : Symbol(String.length, Decl(lib.d.ts, --, --)) |
| 114 | +>n : Symbol(n, Decl(thisTypeInFunctions2.ts, 47, 8)) |
| 115 | +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) |
| 116 | + |
| 117 | + }, |
| 118 | + bar() { |
| 119 | +>bar : Symbol(bar, Decl(thisTypeInFunctions2.ts, 49, 6)) |
| 120 | + |
| 121 | + return 14; |
| 122 | + } |
55 | 123 | })
|
56 | 124 |
|
0 commit comments