Add --noImplicitThis test for object literals

This commit is contained in:
Nathan Shively-Sanders 2016-04-29 16:42:51 -07:00
parent 0a2ba0cc15
commit 8d45a73f12
3 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,22 @@
tests/cases/compiler/noImplicitThisObjectLiterals.ts(2,8): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
tests/cases/compiler/noImplicitThisObjectLiterals.ts(4,16): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
tests/cases/compiler/noImplicitThisObjectLiterals.ts(7,16): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
==== tests/cases/compiler/noImplicitThisObjectLiterals.ts (3 errors) ====
let o = {
d: this, // error, this: any
~~~~
!!! error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
m() {
return this.d.length; // error, this: any
~~~~
!!! error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
},
f: function() {
return this.d.length; // error, this: any
~~~~
!!! error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
}
}

View File

@ -0,0 +1,22 @@
//// [noImplicitThisObjectLiterals.ts]
let o = {
d: this, // error, this: any
m() {
return this.d.length; // error, this: any
},
f: function() {
return this.d.length; // error, this: any
}
}
//// [noImplicitThisObjectLiterals.js]
var o = {
d: this,
m: function () {
return this.d.length; // error, this: any
},
f: function () {
return this.d.length; // error, this: any
}
};

View File

@ -0,0 +1,10 @@
// @noImplicitThis: true
let o = {
d: this, // error, this: any
m() {
return this.d.length; // error, this: any
},
f: function() {
return this.d.length; // error, this: any
}
}