Fixing comment and error message per CR feedback

This commit is contained in:
Anders Hejlsberg 2015-09-26 14:31:03 -07:00
parent abd2a8526d
commit 29f6036176
5 changed files with 67 additions and 66 deletions

View file

@ -3041,8 +3041,9 @@ namespace ts {
return true;
}
// A type is considered independent if it is a built-in type keyword, an array with an element type that is
// considered independent, or a type reference that is considered independent.
// A type is considered independent if it the any, string, number, boolean, symbol, or void keyword, a string
// literal type, an array with an element type that is considered independent, or a type reference that is
// considered independent.
function isIndependentType(node: TypeNode): boolean {
switch (node.kind) {
case SyntaxKind.AnyKeyword:
@ -4368,7 +4369,7 @@ namespace ts {
return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(parent)).thisType;
}
}
error(node, Diagnostics.this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface);
error(node, Diagnostics.A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface);
return unknownType;
}

View file

@ -1652,7 +1652,7 @@
"category": "Error",
"code": 2525
},
"'this' type is available only in a non-static member of a class or interface.": {
"A 'this' type is available only in a non-static member of a class or interface.": {
"category": "Error",
"code": 2526
},

View file

@ -1,7 +1,7 @@
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS2332: 'this' cannot be referenced in current location.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(36,13): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(38,25): error TS2507: Type 'any' is not a constructor function type.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(44,9): error TS2332: 'this' cannot be referenced in current location.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): error TS2332: 'this' cannot be referenced in current location.
@ -51,7 +51,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9):
function genericFunc<T>(x: T) { }
genericFunc<this>(undefined); // Should be an error
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
class ErrClass3 extends this {
~~~~

View file

@ -1,7 +1,7 @@
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS2332: 'this' cannot be referenced in current location.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(36,13): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(38,25): error TS2507: Type 'any' is not a constructor function type.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(44,9): error TS2332: 'this' cannot be referenced in current location.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(45,9): error TS2332: 'this' cannot be referenced in current location.
@ -52,7 +52,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod
function genericFunc<T>(x: T) { }
genericFunc<this>(undefined); // Should be an error
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
class ErrClass3 extends this {
~~~~

View file

@ -1,109 +1,109 @@
tests/cases/conformance/types/thisType/thisTypeErrors.ts(1,9): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(2,14): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(3,9): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(5,16): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(5,23): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(6,12): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(11,13): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(12,14): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(13,18): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(14,23): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(15,15): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(15,22): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(19,13): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(20,14): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(21,18): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(22,23): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(23,15): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(23,22): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(27,15): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(28,17): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(29,19): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(29,26): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(35,19): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(1,9): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(2,14): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(3,9): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(5,16): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(5,23): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(6,12): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(11,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(12,14): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(13,18): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(14,23): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(15,15): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(15,22): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(19,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(20,14): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(21,18): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(22,23): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(23,15): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(23,22): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(27,15): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(28,17): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(29,19): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(29,26): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(35,19): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(36,20): error TS2331: 'this' cannot be referenced in a module or namespace body.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(41,14): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(41,21): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(46,23): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(46,30): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(50,18): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(50,25): error TS2526: 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(41,14): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(41,21): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(46,23): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(46,30): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(50,18): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/types/thisType/thisTypeErrors.ts(50,25): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
==== tests/cases/conformance/types/thisType/thisTypeErrors.ts (30 errors) ====
var x1: this;
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
var x2: { a: this };
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
var x3: this[];
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
function f1(x: this): this {
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
var y: this;
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
return this;
}
interface I1 {
a: { x: this };
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
b: { (): this };
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
c: { new (): this };
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
d: { [x: string]: this };
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
e: { f(x: this): this };
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
}
class C1 {
a: { x: this };
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
b: { (): this };
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
c: { new (): this };
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
d: { [x: string]: this };
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
e: { f(x: this): this };
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
}
class C2 {
static x: this;
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
static y = <this>undefined;
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
static foo(x: this): this {
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
return undefined;
}
}
@ -111,7 +111,7 @@ tests/cases/conformance/types/thisType/thisTypeErrors.ts(50,25): error TS2526: '
namespace N1 {
export var x: this;
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
export var y = this;
~~~~
!!! error TS2331: 'this' cannot be referenced in a module or namespace body.
@ -121,26 +121,26 @@ tests/cases/conformance/types/thisType/thisTypeErrors.ts(50,25): error TS2526: '
x1 = {
g(x: this): this {
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
return undefined;
}
}
f() {
function g(x: this): this {
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
return undefined;
}
let x2 = {
h(x: this): this {
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
~~~~
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
return undefined;
}
}