Add tests+baselines for accessor this parameters
This commit is contained in:
parent
2c70051691
commit
ff1b083ac3
73
tests/baselines/reference/thisTypeInAccessors.js
Normal file
73
tests/baselines/reference/thisTypeInAccessors.js
Normal file
|
@ -0,0 +1,73 @@
|
|||
//// [thisTypeInAccessors.ts]
|
||||
interface Foo {
|
||||
n: number;
|
||||
x: number;
|
||||
}
|
||||
|
||||
const explicit = {
|
||||
n: 12,
|
||||
get x(this: Foo): number { return this.n; },
|
||||
set x(this: Foo, n: number) { this.n = n; }
|
||||
}
|
||||
const copiedFromGetter = {
|
||||
n: 14,
|
||||
get x(this: Foo): number { return this.n; },
|
||||
set x(n) { this.n = n; }
|
||||
}
|
||||
const copiedFromSetter = {
|
||||
n: 15,
|
||||
get x() { return this.n },
|
||||
set x(this: Foo, n: number) { this.n = n; }
|
||||
}
|
||||
|
||||
class Explicit {
|
||||
n = 17;
|
||||
get x(this: Foo): number { return this.n; }
|
||||
set x(this: Foo, n: number) { this.n = n; }
|
||||
}
|
||||
class Contextual {
|
||||
n = 21;
|
||||
get x() { return this.n } // inside a class, so already correct
|
||||
}
|
||||
|
||||
|
||||
//// [thisTypeInAccessors.js]
|
||||
var explicit = {
|
||||
n: 12,
|
||||
get x() { return this.n; },
|
||||
set x(n) { this.n = n; }
|
||||
};
|
||||
var copiedFromGetter = {
|
||||
n: 14,
|
||||
get x() { return this.n; },
|
||||
set x(n) { this.n = n; }
|
||||
};
|
||||
var copiedFromSetter = {
|
||||
n: 15,
|
||||
get x() { return this.n; },
|
||||
set x(n) { this.n = n; }
|
||||
};
|
||||
var Explicit = (function () {
|
||||
function Explicit() {
|
||||
this.n = 17;
|
||||
}
|
||||
Object.defineProperty(Explicit.prototype, "x", {
|
||||
get: function () { return this.n; },
|
||||
set: function (n) { this.n = n; },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return Explicit;
|
||||
}());
|
||||
var Contextual = (function () {
|
||||
function Contextual() {
|
||||
this.n = 21;
|
||||
}
|
||||
Object.defineProperty(Contextual.prototype, "x", {
|
||||
get: function () { return this.n; } // inside a class, so already correct
|
||||
,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return Contextual;
|
||||
}());
|
117
tests/baselines/reference/thisTypeInAccessors.symbols
Normal file
117
tests/baselines/reference/thisTypeInAccessors.symbols
Normal file
|
@ -0,0 +1,117 @@
|
|||
=== tests/cases/conformance/types/thisType/thisTypeInAccessors.ts ===
|
||||
interface Foo {
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInAccessors.ts, 0, 0))
|
||||
|
||||
n: number;
|
||||
>n : Symbol(Foo.n, Decl(thisTypeInAccessors.ts, 0, 15))
|
||||
|
||||
x: number;
|
||||
>x : Symbol(Foo.x, Decl(thisTypeInAccessors.ts, 1, 14))
|
||||
}
|
||||
|
||||
const explicit = {
|
||||
>explicit : Symbol(explicit, Decl(thisTypeInAccessors.ts, 5, 5))
|
||||
|
||||
n: 12,
|
||||
>n : Symbol(n, Decl(thisTypeInAccessors.ts, 5, 18))
|
||||
|
||||
get x(this: Foo): number { return this.n; },
|
||||
>x : Symbol(x, Decl(thisTypeInAccessors.ts, 6, 10), Decl(thisTypeInAccessors.ts, 7, 48))
|
||||
>this : Symbol(this, Decl(thisTypeInAccessors.ts, 7, 10))
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInAccessors.ts, 0, 0))
|
||||
>this.n : Symbol(Foo.n, Decl(thisTypeInAccessors.ts, 0, 15))
|
||||
>this : Symbol(Foo, Decl(thisTypeInAccessors.ts, 0, 0))
|
||||
>n : Symbol(Foo.n, Decl(thisTypeInAccessors.ts, 0, 15))
|
||||
|
||||
set x(this: Foo, n: number) { this.n = n; }
|
||||
>x : Symbol(x, Decl(thisTypeInAccessors.ts, 6, 10), Decl(thisTypeInAccessors.ts, 7, 48))
|
||||
>this : Symbol(this, Decl(thisTypeInAccessors.ts, 8, 10))
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInAccessors.ts, 0, 0))
|
||||
>n : Symbol(n, Decl(thisTypeInAccessors.ts, 8, 20))
|
||||
>this.n : Symbol(Foo.n, Decl(thisTypeInAccessors.ts, 0, 15))
|
||||
>this : Symbol(Foo, Decl(thisTypeInAccessors.ts, 0, 0))
|
||||
>n : Symbol(Foo.n, Decl(thisTypeInAccessors.ts, 0, 15))
|
||||
>n : Symbol(n, Decl(thisTypeInAccessors.ts, 8, 20))
|
||||
}
|
||||
const copiedFromGetter = {
|
||||
>copiedFromGetter : Symbol(copiedFromGetter, Decl(thisTypeInAccessors.ts, 10, 5))
|
||||
|
||||
n: 14,
|
||||
>n : Symbol(n, Decl(thisTypeInAccessors.ts, 10, 26))
|
||||
|
||||
get x(this: Foo): number { return this.n; },
|
||||
>x : Symbol(x, Decl(thisTypeInAccessors.ts, 11, 10), Decl(thisTypeInAccessors.ts, 12, 48))
|
||||
>this : Symbol(this, Decl(thisTypeInAccessors.ts, 12, 10))
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInAccessors.ts, 0, 0))
|
||||
>this.n : Symbol(Foo.n, Decl(thisTypeInAccessors.ts, 0, 15))
|
||||
>this : Symbol(Foo, Decl(thisTypeInAccessors.ts, 0, 0))
|
||||
>n : Symbol(Foo.n, Decl(thisTypeInAccessors.ts, 0, 15))
|
||||
|
||||
set x(n) { this.n = n; }
|
||||
>x : Symbol(x, Decl(thisTypeInAccessors.ts, 11, 10), Decl(thisTypeInAccessors.ts, 12, 48))
|
||||
>n : Symbol(n, Decl(thisTypeInAccessors.ts, 13, 10))
|
||||
>this.n : Symbol(Foo.n, Decl(thisTypeInAccessors.ts, 0, 15))
|
||||
>this : Symbol(Foo, Decl(thisTypeInAccessors.ts, 0, 0))
|
||||
>n : Symbol(Foo.n, Decl(thisTypeInAccessors.ts, 0, 15))
|
||||
>n : Symbol(n, Decl(thisTypeInAccessors.ts, 13, 10))
|
||||
}
|
||||
const copiedFromSetter = {
|
||||
>copiedFromSetter : Symbol(copiedFromSetter, Decl(thisTypeInAccessors.ts, 15, 5))
|
||||
|
||||
n: 15,
|
||||
>n : Symbol(n, Decl(thisTypeInAccessors.ts, 15, 26))
|
||||
|
||||
get x() { return this.n },
|
||||
>x : Symbol(x, Decl(thisTypeInAccessors.ts, 16, 10), Decl(thisTypeInAccessors.ts, 17, 30))
|
||||
>this.n : Symbol(Foo.n, Decl(thisTypeInAccessors.ts, 0, 15))
|
||||
>this : Symbol(Foo, Decl(thisTypeInAccessors.ts, 0, 0))
|
||||
>n : Symbol(Foo.n, Decl(thisTypeInAccessors.ts, 0, 15))
|
||||
|
||||
set x(this: Foo, n: number) { this.n = n; }
|
||||
>x : Symbol(x, Decl(thisTypeInAccessors.ts, 16, 10), Decl(thisTypeInAccessors.ts, 17, 30))
|
||||
>this : Symbol(this, Decl(thisTypeInAccessors.ts, 18, 10))
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInAccessors.ts, 0, 0))
|
||||
>n : Symbol(n, Decl(thisTypeInAccessors.ts, 18, 20))
|
||||
>this.n : Symbol(Foo.n, Decl(thisTypeInAccessors.ts, 0, 15))
|
||||
>this : Symbol(Foo, Decl(thisTypeInAccessors.ts, 0, 0))
|
||||
>n : Symbol(Foo.n, Decl(thisTypeInAccessors.ts, 0, 15))
|
||||
>n : Symbol(n, Decl(thisTypeInAccessors.ts, 18, 20))
|
||||
}
|
||||
|
||||
class Explicit {
|
||||
>Explicit : Symbol(Explicit, Decl(thisTypeInAccessors.ts, 19, 1))
|
||||
|
||||
n = 17;
|
||||
>n : Symbol(Explicit.n, Decl(thisTypeInAccessors.ts, 21, 16))
|
||||
|
||||
get x(this: Foo): number { return this.n; }
|
||||
>x : Symbol(Explicit.x, Decl(thisTypeInAccessors.ts, 22, 11), Decl(thisTypeInAccessors.ts, 23, 47))
|
||||
>this : Symbol(this, Decl(thisTypeInAccessors.ts, 23, 10))
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInAccessors.ts, 0, 0))
|
||||
>this.n : Symbol(Foo.n, Decl(thisTypeInAccessors.ts, 0, 15))
|
||||
>this : Symbol(Foo, Decl(thisTypeInAccessors.ts, 0, 0))
|
||||
>n : Symbol(Foo.n, Decl(thisTypeInAccessors.ts, 0, 15))
|
||||
|
||||
set x(this: Foo, n: number) { this.n = n; }
|
||||
>x : Symbol(Explicit.x, Decl(thisTypeInAccessors.ts, 22, 11), Decl(thisTypeInAccessors.ts, 23, 47))
|
||||
>this : Symbol(this, Decl(thisTypeInAccessors.ts, 24, 10))
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInAccessors.ts, 0, 0))
|
||||
>n : Symbol(n, Decl(thisTypeInAccessors.ts, 24, 20))
|
||||
>this.n : Symbol(Foo.n, Decl(thisTypeInAccessors.ts, 0, 15))
|
||||
>this : Symbol(Foo, Decl(thisTypeInAccessors.ts, 0, 0))
|
||||
>n : Symbol(Foo.n, Decl(thisTypeInAccessors.ts, 0, 15))
|
||||
>n : Symbol(n, Decl(thisTypeInAccessors.ts, 24, 20))
|
||||
}
|
||||
class Contextual {
|
||||
>Contextual : Symbol(Contextual, Decl(thisTypeInAccessors.ts, 25, 1))
|
||||
|
||||
n = 21;
|
||||
>n : Symbol(Contextual.n, Decl(thisTypeInAccessors.ts, 26, 18))
|
||||
|
||||
get x() { return this.n } // inside a class, so already correct
|
||||
>x : Symbol(Contextual.x, Decl(thisTypeInAccessors.ts, 27, 11))
|
||||
>this.n : Symbol(Contextual.n, Decl(thisTypeInAccessors.ts, 26, 18))
|
||||
>this : Symbol(Contextual, Decl(thisTypeInAccessors.ts, 25, 1))
|
||||
>n : Symbol(Contextual.n, Decl(thisTypeInAccessors.ts, 26, 18))
|
||||
}
|
||||
|
129
tests/baselines/reference/thisTypeInAccessors.types
Normal file
129
tests/baselines/reference/thisTypeInAccessors.types
Normal file
|
@ -0,0 +1,129 @@
|
|||
=== tests/cases/conformance/types/thisType/thisTypeInAccessors.ts ===
|
||||
interface Foo {
|
||||
>Foo : Foo
|
||||
|
||||
n: number;
|
||||
>n : number
|
||||
|
||||
x: number;
|
||||
>x : number
|
||||
}
|
||||
|
||||
const explicit = {
|
||||
>explicit : { n: number; x: number; }
|
||||
>{ n: 12, get x(this: Foo): number { return this.n; }, set x(this: Foo, n: number) { this.n = n; }} : { n: number; x: number; }
|
||||
|
||||
n: 12,
|
||||
>n : number
|
||||
>12 : number
|
||||
|
||||
get x(this: Foo): number { return this.n; },
|
||||
>x : number
|
||||
>this : Foo
|
||||
>Foo : Foo
|
||||
>this.n : number
|
||||
>this : Foo
|
||||
>n : number
|
||||
|
||||
set x(this: Foo, n: number) { this.n = n; }
|
||||
>x : number
|
||||
>this : Foo
|
||||
>Foo : Foo
|
||||
>n : number
|
||||
>this.n = n : number
|
||||
>this.n : number
|
||||
>this : Foo
|
||||
>n : number
|
||||
>n : number
|
||||
}
|
||||
const copiedFromGetter = {
|
||||
>copiedFromGetter : { n: number; x: number; }
|
||||
>{ n: 14, get x(this: Foo): number { return this.n; }, set x(n) { this.n = n; }} : { n: number; x: number; }
|
||||
|
||||
n: 14,
|
||||
>n : number
|
||||
>14 : number
|
||||
|
||||
get x(this: Foo): number { return this.n; },
|
||||
>x : number
|
||||
>this : Foo
|
||||
>Foo : Foo
|
||||
>this.n : number
|
||||
>this : Foo
|
||||
>n : number
|
||||
|
||||
set x(n) { this.n = n; }
|
||||
>x : number
|
||||
>n : number
|
||||
>this.n = n : number
|
||||
>this.n : number
|
||||
>this : Foo
|
||||
>n : number
|
||||
>n : number
|
||||
}
|
||||
const copiedFromSetter = {
|
||||
>copiedFromSetter : { n: number; x: number; }
|
||||
>{ n: 15, get x() { return this.n }, set x(this: Foo, n: number) { this.n = n; }} : { n: number; x: number; }
|
||||
|
||||
n: 15,
|
||||
>n : number
|
||||
>15 : number
|
||||
|
||||
get x() { return this.n },
|
||||
>x : number
|
||||
>this.n : number
|
||||
>this : Foo
|
||||
>n : number
|
||||
|
||||
set x(this: Foo, n: number) { this.n = n; }
|
||||
>x : number
|
||||
>this : Foo
|
||||
>Foo : Foo
|
||||
>n : number
|
||||
>this.n = n : number
|
||||
>this.n : number
|
||||
>this : Foo
|
||||
>n : number
|
||||
>n : number
|
||||
}
|
||||
|
||||
class Explicit {
|
||||
>Explicit : Explicit
|
||||
|
||||
n = 17;
|
||||
>n : number
|
||||
>17 : number
|
||||
|
||||
get x(this: Foo): number { return this.n; }
|
||||
>x : number
|
||||
>this : Foo
|
||||
>Foo : Foo
|
||||
>this.n : number
|
||||
>this : Foo
|
||||
>n : number
|
||||
|
||||
set x(this: Foo, n: number) { this.n = n; }
|
||||
>x : number
|
||||
>this : Foo
|
||||
>Foo : Foo
|
||||
>n : number
|
||||
>this.n = n : number
|
||||
>this.n : number
|
||||
>this : Foo
|
||||
>n : number
|
||||
>n : number
|
||||
}
|
||||
class Contextual {
|
||||
>Contextual : Contextual
|
||||
|
||||
n = 21;
|
||||
>n : number
|
||||
>21 : number
|
||||
|
||||
get x() { return this.n } // inside a class, so already correct
|
||||
>x : number
|
||||
>this.n : number
|
||||
>this : this
|
||||
>n : number
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
tests/cases/conformance/types/thisType/thisTypeInAccessorsNegative.ts(10,9): error TS2682: 'get' and 'set' accessor must have the same 'this' type.
|
||||
tests/cases/conformance/types/thisType/thisTypeInAccessorsNegative.ts(11,9): error TS2682: 'get' and 'set' accessor must have the same 'this' type.
|
||||
tests/cases/conformance/types/thisType/thisTypeInAccessorsNegative.ts(16,22): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/thisType/thisTypeInAccessorsNegative.ts (3 errors) ====
|
||||
interface Foo {
|
||||
n: number;
|
||||
x: number;
|
||||
}
|
||||
interface Bar {
|
||||
wrong: "place" | "time" | "method" | "technique";
|
||||
}
|
||||
const mismatch = {
|
||||
n: 13,
|
||||
get x(this: Foo) { return this.n; },
|
||||
~
|
||||
!!! error TS2682: 'get' and 'set' accessor must have the same 'this' type.
|
||||
set x(this: Bar, n) { this.wrong = "method"; }
|
||||
~
|
||||
!!! error TS2682: 'get' and 'set' accessor must have the same 'this' type.
|
||||
}
|
||||
const contextual: Foo = {
|
||||
n: 16,
|
||||
// there is no contextual this type from an Foo.x.
|
||||
get x() { return this.n; }
|
||||
~~~~
|
||||
!!! error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
|
||||
}
|
||||
|
31
tests/baselines/reference/thisTypeInAccessorsNegative.js
Normal file
31
tests/baselines/reference/thisTypeInAccessorsNegative.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
//// [thisTypeInAccessorsNegative.ts]
|
||||
interface Foo {
|
||||
n: number;
|
||||
x: number;
|
||||
}
|
||||
interface Bar {
|
||||
wrong: "place" | "time" | "method" | "technique";
|
||||
}
|
||||
const mismatch = {
|
||||
n: 13,
|
||||
get x(this: Foo) { return this.n; },
|
||||
set x(this: Bar, n) { this.wrong = "method"; }
|
||||
}
|
||||
const contextual: Foo = {
|
||||
n: 16,
|
||||
// there is no contextual this type from an Foo.x.
|
||||
get x() { return this.n; }
|
||||
}
|
||||
|
||||
|
||||
//// [thisTypeInAccessorsNegative.js]
|
||||
var mismatch = {
|
||||
n: 13,
|
||||
get x() { return this.n; },
|
||||
set x(n) { this.wrong = "method"; }
|
||||
};
|
||||
var contextual = {
|
||||
n: 16,
|
||||
// there is no contextual this type from an Foo.x.
|
||||
get x() { return this.n; }
|
||||
};
|
|
@ -75,32 +75,31 @@ tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(146,1): er
|
|||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(148,1): error TS2322: Type '(this: Base2) => number' is not assignable to type '(this: Base1) => number'.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(154,16): error TS2679: A function that is called with the 'new' keyword cannot have a 'this' type that is 'void'.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(158,17): error TS2681: A constructor cannot have a 'this' parameter.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(160,11): error TS2682: A setter cannot have a 'this' parameter.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(164,9): error TS2681: A constructor cannot have a 'this' parameter.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(166,31): error TS2681: A constructor cannot have a 'this' parameter.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(167,30): error TS2680: A 'this' parameter must be the first parameter.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(170,26): error TS1003: Identifier expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(170,30): error TS1005: ',' expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(171,20): error TS2370: A rest parameter must be of an array type.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(171,23): error TS1003: Identifier expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(171,27): error TS1005: ',' expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(172,23): error TS1005: ',' expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(172,24): error TS1138: Parameter declaration expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(173,28): error TS1003: Identifier expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(173,32): error TS1005: ',' expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(174,30): error TS1005: ',' expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(174,32): error TS1138: Parameter declaration expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(174,39): error TS1005: ';' expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(174,40): error TS1128: Declaration or statement expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(174,42): error TS2304: Cannot find name 'number'.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(174,49): error TS1005: ';' expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(177,1): error TS7027: Unreachable code detected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(177,29): error TS2304: Cannot find name 'm'.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(177,32): error TS1005: ';' expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(177,35): error TS2304: Cannot find name 'm'.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(162,9): error TS2681: A constructor cannot have a 'this' parameter.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(164,31): error TS2681: A constructor cannot have a 'this' parameter.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(165,30): error TS2680: A 'this' parameter must be the first parameter.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(168,26): error TS1003: Identifier expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(168,30): error TS1005: ',' expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(169,20): error TS2370: A rest parameter must be of an array type.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(169,23): error TS1003: Identifier expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(169,27): error TS1005: ',' expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(170,23): error TS1005: ',' expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(170,24): error TS1138: Parameter declaration expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(171,28): error TS1003: Identifier expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(171,32): error TS1005: ',' expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(172,30): error TS1005: ',' expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(172,32): error TS1138: Parameter declaration expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(172,39): error TS1005: ';' expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(172,40): error TS1128: Declaration or statement expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(172,42): error TS2304: Cannot find name 'number'.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(172,49): error TS1005: ';' expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(175,1): error TS7027: Unreachable code detected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(175,29): error TS2304: Cannot find name 'm'.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(175,32): error TS1005: ';' expected.
|
||||
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(175,35): error TS2304: Cannot find name 'm'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts (66 errors) ====
|
||||
==== tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts (65 errors) ====
|
||||
class C {
|
||||
n: number;
|
||||
explicitThis(this: this, m: number): number {
|
||||
|
@ -380,10 +379,6 @@ tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(177,35): e
|
|||
~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2681: A constructor cannot have a 'this' parameter.
|
||||
}
|
||||
set p(this: void) {
|
||||
~~~~~~~~~~
|
||||
!!! error TS2682: A setter cannot have a 'this' parameter.
|
||||
}
|
||||
}
|
||||
interface ThisConstructorInterface {
|
||||
new(this: ThisConstructor, n: number);
|
||||
|
|
|
@ -158,8 +158,6 @@ let voidThis = new VoidThis();
|
|||
class ThisConstructor {
|
||||
constructor(this: ThisConstructor, private n: number) {
|
||||
}
|
||||
set p(this: void) {
|
||||
}
|
||||
}
|
||||
interface ThisConstructorInterface {
|
||||
new(this: ThisConstructor, n: number);
|
||||
|
@ -332,12 +330,6 @@ var ThisConstructor = (function () {
|
|||
function ThisConstructor(n) {
|
||||
this.n = n;
|
||||
}
|
||||
Object.defineProperty(ThisConstructor.prototype, "p", {
|
||||
set: function () {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return ThisConstructor;
|
||||
}());
|
||||
var thisConstructorType;
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
// @noImplicitAny: true
|
||||
// @noImplicitThis: true
|
||||
// @target: es5
|
||||
interface Foo {
|
||||
n: number;
|
||||
x: number;
|
||||
}
|
||||
|
||||
const explicit = {
|
||||
n: 12,
|
||||
get x(this: Foo): number { return this.n; },
|
||||
set x(this: Foo, n: number) { this.n = n; }
|
||||
}
|
||||
const copiedFromGetter = {
|
||||
n: 14,
|
||||
get x(this: Foo): number { return this.n; },
|
||||
set x(n) { this.n = n; }
|
||||
}
|
||||
const copiedFromSetter = {
|
||||
n: 15,
|
||||
get x() { return this.n },
|
||||
set x(this: Foo, n: number) { this.n = n; }
|
||||
}
|
||||
|
||||
class Explicit {
|
||||
n = 17;
|
||||
get x(this: Foo): number { return this.n; }
|
||||
set x(this: Foo, n: number) { this.n = n; }
|
||||
}
|
||||
class Contextual {
|
||||
n = 21;
|
||||
get x() { return this.n } // inside a class, so already correct
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
// @noImplicitAny: true
|
||||
// @noImplicitThis: true
|
||||
// @target: es5
|
||||
interface Foo {
|
||||
n: number;
|
||||
x: number;
|
||||
}
|
||||
interface Bar {
|
||||
wrong: "place" | "time" | "method" | "technique";
|
||||
}
|
||||
const mismatch = {
|
||||
n: 13,
|
||||
get x(this: Foo) { return this.n; },
|
||||
set x(this: Bar, n) { this.wrong = "method"; }
|
||||
}
|
||||
const contextual: Foo = {
|
||||
n: 16,
|
||||
// there is no contextual this type from an Foo.x.
|
||||
get x() { return this.n; }
|
||||
}
|
|
@ -157,8 +157,6 @@ let voidThis = new VoidThis();
|
|||
class ThisConstructor {
|
||||
constructor(this: ThisConstructor, private n: number) {
|
||||
}
|
||||
set p(this: void) {
|
||||
}
|
||||
}
|
||||
interface ThisConstructorInterface {
|
||||
new(this: ThisConstructor, n: number);
|
||||
|
|
Loading…
Reference in a new issue