|
| 1 | +tests/cases/conformance/types/thisType/thisTypeInAccessors.ts(8,11): error TS2784: 'get' and 'set' accessors cannot declare 'this' parameters. |
| 2 | +tests/cases/conformance/types/thisType/thisTypeInAccessors.ts(9,11): error TS2784: 'get' and 'set' accessors cannot declare 'this' parameters. |
| 3 | +tests/cases/conformance/types/thisType/thisTypeInAccessors.ts(13,11): error TS2784: 'get' and 'set' accessors cannot declare 'this' parameters. |
| 4 | +tests/cases/conformance/types/thisType/thisTypeInAccessors.ts(19,11): error TS2784: 'get' and 'set' accessors cannot declare 'this' parameters. |
| 5 | +tests/cases/conformance/types/thisType/thisTypeInAccessors.ts(23,11): error TS2784: 'get' and 'set' accessors cannot declare 'this' parameters. |
| 6 | +tests/cases/conformance/types/thisType/thisTypeInAccessors.ts(24,11): error TS2784: 'get' and 'set' accessors cannot declare 'this' parameters. |
| 7 | +tests/cases/conformance/types/thisType/thisTypeInAccessors.ts(29,11): error TS2784: 'get' and 'set' accessors cannot declare 'this' parameters. |
| 8 | +tests/cases/conformance/types/thisType/thisTypeInAccessors.ts(30,11): error TS2784: 'get' and 'set' accessors cannot declare 'this' parameters. |
| 9 | + |
| 10 | + |
| 11 | +==== tests/cases/conformance/types/thisType/thisTypeInAccessors.ts (8 errors) ==== |
| 12 | + interface Foo { |
| 13 | + n: number; |
| 14 | + x: number; |
| 15 | + } |
| 16 | + |
| 17 | + const explicit = { |
| 18 | + n: 12, |
| 19 | + get x(this: Foo): number { return this.n; }, |
| 20 | + ~~~~~~~~~ |
| 21 | +!!! error TS2784: 'get' and 'set' accessors cannot declare 'this' parameters. |
| 22 | + set x(this: Foo, n: number) { this.n = n; } |
| 23 | + ~~~~~~~~~ |
| 24 | +!!! error TS2784: 'get' and 'set' accessors cannot declare 'this' parameters. |
| 25 | + } |
| 26 | + const copiedFromGetter = { |
| 27 | + n: 14, |
| 28 | + get x(this: Foo): number { return this.n; }, |
| 29 | + ~~~~~~~~~ |
| 30 | +!!! error TS2784: 'get' and 'set' accessors cannot declare 'this' parameters. |
| 31 | + set x(n) { this.n = n; } |
| 32 | + } |
| 33 | + const copiedFromSetter = { |
| 34 | + n: 15, |
| 35 | + get x() { return this.n }, |
| 36 | + set x(this: Foo, n: number) { this.n = n; } |
| 37 | + ~~~~~~~~~ |
| 38 | +!!! error TS2784: 'get' and 'set' accessors cannot declare 'this' parameters. |
| 39 | + } |
| 40 | + const copiedFromGetterUnannotated = { |
| 41 | + n: 16, |
| 42 | + get x(this: Foo) { return this.n }, |
| 43 | + ~~~~~~~~~ |
| 44 | +!!! error TS2784: 'get' and 'set' accessors cannot declare 'this' parameters. |
| 45 | + set x(this, n) { this.n = n; } |
| 46 | + ~~~~ |
| 47 | +!!! error TS2784: 'get' and 'set' accessors cannot declare 'this' parameters. |
| 48 | + } |
| 49 | + |
| 50 | + class Explicit { |
| 51 | + n = 17; |
| 52 | + get x(this: Foo): number { return this.n; } |
| 53 | + ~~~~~~~~~ |
| 54 | +!!! error TS2784: 'get' and 'set' accessors cannot declare 'this' parameters. |
| 55 | + set x(this: Foo, n: number) { this.n = n; } |
| 56 | + ~~~~~~~~~ |
| 57 | +!!! error TS2784: 'get' and 'set' accessors cannot declare 'this' parameters. |
| 58 | + } |
| 59 | + class Contextual { |
| 60 | + n = 21; |
| 61 | + get x() { return this.n } // inside a class, so already correct |
| 62 | + } |
| 63 | + |
0 commit comments