8000 Typed 'this' in object literal methods by ahejlsberg · Pull Request #14141 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content

Typed 'this' in object literal methods #14141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f6a3a3f
Use '__this__' property in contextual type to indicate type of 'this'
ahejlsberg Feb 14, 2017
8cd6c5d
Introduce ThisType<T> marker interface
ahejlsberg Feb 17, 2017
2ca6164
Default contextual 'this' type is containing object literal
ahejlsberg Feb 17, 2017
e512376
Update tests
ahejlsberg Feb 17, 2017
d7e153d
Accept new baselines
ahejlsberg Feb 17, 2017
fe32bb7
Merge branch 'master' into contextualThisType
ahejlsberg Feb 17, 2017
27346b1
Accept new baselines
ahejlsberg Feb 17, 2017
e3a0687
Contextual this in 'obj.xxx = function(...)' or 'obj[xxx] = function(…
ahejlsberg Feb 17, 2017
168d367
Contextually type 'this' in accessors of object literals
ahejlsberg Feb 23, 2017
c2d8a59
Accept new baselines
ahejlsberg Feb 23, 2017
ec292c9
Update test
ahejlsberg Feb 23, 2017
9b6b6cc
Fix linting error
ahejlsberg Feb 23, 2017
9dc2bae
Use contextual type of object literal as 'this' in methods
ahejlsberg Feb 25, 2017
16f4030
Accept new baselines
ahejlsberg Feb 25, 2017
20b4523
Rename applyToContextualType to mapType and remove old mapType
ahejlsberg Feb 25, 2017
6fdd929
Update test
ahejlsberg Feb 25, 2017
cd87d90
Update comment
ahejlsberg Feb 27, 2017
5bda48b
Add tests
ahejlsberg Feb 27, 2017
993397b
Introduce CheckMode enum and getContextualMapper() function
ahejlsberg Feb 28, 2017
ff2cfd2
Update test
ahejlsberg Feb 28, 2017
c87c124
Accept new baselines
ahejlsberg Feb 28, 2017
ee7b93c
Merge branch 'master' into contextualThisType
ahejlsberg Feb 28, 2017
21c4300
Enable new behavior only in --noImplicitThis mode
ahejlsberg Mar 1, 2017
25738a8
Update tests
ahejlsberg Mar 1, 2017
f77cd8e
Accept new baselines
ahejlsberg Mar 1, 2017
9d1b325
Update another test
ahejlsberg Mar 1, 2017
7561cdf
Add ThisType<any> to Object.{create|defineProperty|defineProperties}
ahejlsberg Mar 2, 2017
258bb4f
Accept new baselines
ahejlsberg Mar 2, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Accept new baselines
  • Loading branch information
ahejlsberg committed Feb 23, 2017
commit c2d8a593b9eb9642d7a2bc57d4cd49bdd85c206e
7 changes: 7 additions & 0 deletions tests/baselines/reference/commentsOnObjectLiteral3.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ var v = {
>a : Symbol(a, Decl(commentsOnObjectLiteral3.ts, 8, 13), Decl(commentsOnObjectLiteral3.ts, 12, 18))
10000
return this.prop;
>this.prop : Symbol(prop, Decl(commentsOnObjectLiteral3.ts, 1, 9))
>this : Symbol(v, Decl(commentsOnObjectLiteral3.ts, 1, 7))
>prop : Symbol(prop, Decl(commentsOnObjectLiteral3.ts, 1, 9))

} /*trailing 1*/,
//setter
set a(value) {
>a : Symbol(a, Decl(commentsOnObjectLiteral3.ts, 8, 13), Decl(commentsOnObjectLiteral3.ts, 12, 18))
>value : Symbol(value, Decl(commentsOnObjectLiteral3.ts, 14, 7))

this.prop = value;
>this.prop : Symbol(prop, Decl(commentsOnObjectLiteral3.ts, 1, 9))
>this : Symbol(v, Decl(commentsOnObjectLiteral3.ts, 1, 7))
>prop : Symbol(prop, Decl(commentsOnObjectLiteral3.ts, 1, 9))
>value : Symbol(value, Decl(commentsOnObjectLiteral3.ts, 14, 7))

} // trailing 2
Expand Down
26 changes: 13 additions & 13 deletions tests/baselines/reference/commentsOnObjectLiteral3.types
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
=== tests/cases/compiler/commentsOnObjectLiteral3.ts ===

var v = {
>v : { prop: number; func: () => void; func1(): void; a: any; }
>{ //property prop: 1 /* multiple trailing comments */ /*trailing comments*/, //property func: function () { }, //PropertyName + CallSignature func1() { }, //getter get a() { return this.prop; } /*trailing 1*/, //setter set a(value) { this.prop = value; } // trailing 2} : { prop: number; func: () => void; func1(): void; a: any; }
>v : { prop: number; func: () => void; func1(): void; a: number; }
>{ //property prop: 1 /* multiple trailing comments */ /*trailing comments*/, //property func: function () { }, //PropertyName + CallSignature func1() { }, //getter get a() { return this.prop; } /*trailing 1*/, //setter set a(value) { this.prop = value; } // trailing 2} : { prop: number; func: () => void; func1(): void; a: number; }

//property
prop: 1 /* multiple trailing comments */ /*trailing comments*/,
Expand All @@ -21,25 +21,25 @@ var v = {

//getter
get a() {
>a : any
>a : number

return this.prop;
>this.prop : any
>this : any
>prop : any
>this.prop : number
>this : { prop: number; func: () => void; func1(): void; a: number; }
>prop : number

} /*trailing 1*/,
//setter
set a(value) {
>a : any
>value : any
>a : number
>value : number

this.prop = value;
>this.prop = value : any
>this.prop : any
>this : any
>prop : any
>value : any
>this.prop = value : number
>this.prop : number
>this : { prop: number; func: () => void; func1(): void; a: number; }
>prop : number
>value : number

} // trailing 2
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ function /*1*/makePoint(x: number) {
set x(a: number) { this.b = a; }
>x : Symbol(x, Decl(declFileObjectLiteralWithAccessors.ts, 3, 14), Decl(declFileObjectLiteralWithAccessors.ts, 4, 30))
>a : Symbol(a, Decl(declFileObjectLiteralWithAccessors.ts, 5, 14))
>this.b : Symbol(b, Decl(declFileObjectLiteralWithAccessors.ts, 2, 12))
>this : Symbol(__object, Decl(declFileObjectLiteralWithAccessors.ts, 2, 10))
>b : Symbol(b, Decl(declFileObjectLiteralWithAccessors.ts, 2, 12))
>a : Symbol(a, Decl(declFileObjectLiteralWithAccessors.ts, 5, 14))

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ function /*1*/makePoint(x: number) {
>x : number
>a : number
>this.b = a : number
>this.b : any
>this : any
>b : any
>this.b : number
>this : { b: number; x: number; }
>b : number
>a : number

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ function /*1*/makePoint(x: number) {
set x(a: number) { this.b = a; }
>x : Symbol(x, Decl(declFileObjectLiteralWithOnlySetter.ts, 3, 14))
>a : Symbol(a, Decl(declFileObjectLiteralWithOnlySetter.ts, 4, 14))
>this.b : Symbol(b, Decl(declFileObjectLiteralWithOnlySetter.ts, 2, 12))
>this : Symbol(__object, Decl(declFileObjectLiteralWithOnlySetter.ts, 2, 10))
>b : Symbol(b, Decl(declFileObjectLiteralWithOnlySetter.ts, 2, 12))
>a : Symbol(a, Decl(declFileObjectLiteralWithOnlySetter.ts, 4, 14))

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ function /*1*/makePoint(x: number) {
>x : number
>a : number
>this.b = a : number
>this.b : any
>this : any
>b : any
>this.b : number
>this : { b: number; x: number; }
>b : number
>a : number

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ var object = {

get 0() {
return this._0;
>this._0 : Symbol(_0, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 14))
>this : Symbol(object, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 12))
>_0 : Symbol(_0, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 14))

},
set 0(x: number) {
>x : Symbol(x, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 6, 10))

this._0 = x;
>this._0 : Symbol(_0, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 14))
>this : Symbol(object, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 12))
>_0 : Symbol(_0, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 14))
>x : Symbol(x, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 6, 10))

},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ var object = {

get 0() {
return this._0;
>this._0 : any
>this : any
>_0 : any
>this._0 : number
>this : { _0: number; 0: number; }
>_0 : number

},
set 0(x: number) {
>x : number

this._0 = x;
>this._0 = x : number
>this._0 : any
>this : any
>_0 : any
>this._0 : number
>this : { _0: number; 0: number; }
>_0 : number
>x : number

},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
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) ====
==== tests/cases/conformance/types/thisType/thisTypeInAccessorsNegative.ts (2 errors) ====
interface Foo {
n: number;
x: number;
Expand All @@ -24,7 +23,5 @@ tests/cases/conformance/types/thisType/thisTypeInAccessorsNegative.ts(16,22): er
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.
}

0