mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-23 10:29:01 -06:00
25840 - Add a more meaningful error message to the case when calling a public static method on an instance (#25922)
* add a more meaningful error message to the case when calling a public static method on an instance * Fix tests
This commit is contained in:
parent
d8cbe34a05
commit
37b9a6bca4
@ -3322,7 +3322,6 @@ namespace ts {
|
||||
// Anonymous types without a symbol are never circular.
|
||||
return createTypeNodeFromObjectType(type);
|
||||
}
|
||||
|
||||
function shouldWriteTypeOfFunctionSymbol() {
|
||||
const isStaticMethodSymbol = !!(symbol.flags & SymbolFlags.Method) && // typeof static method
|
||||
some(symbol.declarations, declaration => hasModifier(declaration, ModifierFlags.Static));
|
||||
@ -9158,7 +9157,10 @@ namespace ts {
|
||||
}
|
||||
if (accessExpression && !isConstEnumObjectType(objectType)) {
|
||||
if (noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors) {
|
||||
if (getIndexTypeOfType(objectType, IndexKind.Number)) {
|
||||
if (propName !== undefined && typeHasStaticProperty(propName, objectType)) {
|
||||
error(accessExpression, Diagnostics.Property_0_is_a_static_member_of_type_1, propName as string, typeToString(objectType));
|
||||
}
|
||||
else if (getIndexTypeOfType(objectType, IndexKind.Number)) {
|
||||
error(accessExpression.argumentExpression, Diagnostics.Element_implicitly_has_an_any_type_because_index_expression_is_not_of_type_number);
|
||||
}
|
||||
else {
|
||||
@ -18055,22 +18057,26 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
const promisedType = getPromisedTypeOfPromise(containingType);
|
||||
if (promisedType && getPropertyOfType(promisedType, propNode.escapedText)) {
|
||||
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await, declarationNameToString(propNode), typeToString(containingType));
|
||||
if (typeHasStaticProperty(propNode.escapedText, containingType)) {
|
||||
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_is_a_static_member_of_type_1, declarationNameToString(propNode), typeToString(containingType));
|
||||
}
|
||||
else {
|
||||
const suggestion = getSuggestedSymbolForNonexistentProperty(propNode, containingType);
|
||||
if (suggestion !== undefined) {
|
||||
const suggestedName = symbolName(suggestion);
|
||||
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, declarationNameToString(propNode), typeToString(containingType), suggestedName);
|
||||
relatedInfo = suggestion.valueDeclaration && createDiagnosticForNode(suggestion.valueDeclaration, Diagnostics._0_is_declared_here, suggestedName);
|
||||
const promisedType = getPromisedTypeOfPromise(containingType);
|
||||
if (promisedType && getPropertyOfType(promisedType, propNode.escapedText)) {
|
||||
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await, declarationNameToString(propNode), typeToString(containingType));
|
||||
}
|
||||
else {
|
||||
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
|
||||
const suggestion = getSuggestedSymbolForNonexistentProperty(propNode, containingType);
|
||||
if (suggestion !== undefined) {
|
||||
const suggestedName = symbolName(suggestion);
|
||||
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, declarationNameToString(propNode), typeToString(containingType), suggestedName);
|
||||
relatedInfo = suggestion.valueDeclaration && createDiagnosticForNode(suggestion.valueDeclaration, Diagnostics._0_is_declared_here, suggestedName);
|
||||
}
|
||||
else {
|
||||
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const resultDiagnostic = createDiagnosticForNodeFromMessageChain(propNode, errorInfo);
|
||||
if (relatedInfo) {
|
||||
addRelatedInfo(resultDiagnostic, relatedInfo);
|
||||
@ -18078,6 +18084,11 @@ namespace ts {
|
||||
diagnostics.add(resultDiagnostic);
|
||||
}
|
||||
|
||||
function typeHasStaticProperty(propName: __String, containingType: Type): boolean {
|
||||
const prop = containingType.symbol && getPropertyOfType(getTypeOfSymbol(containingType.symbol), propName);
|
||||
return prop !== undefined && prop.valueDeclaration && hasModifier(prop.valueDeclaration, ModifierFlags.Static);
|
||||
}
|
||||
|
||||
function getSuggestedSymbolForNonexistentProperty(name: Identifier | string, containingType: Type): Symbol | undefined {
|
||||
return getSpellingSuggestionForName(isString(name) ? name : idText(name), getPropertiesOfType(containingType), SymbolFlags.Value);
|
||||
}
|
||||
|
||||
@ -2064,6 +2064,10 @@
|
||||
"category": "Error",
|
||||
"code": 2575
|
||||
},
|
||||
"Property '{0}' is a static member of type '{1}'": {
|
||||
"category": "Error",
|
||||
"code": 2576
|
||||
},
|
||||
"JSX element attributes type '{0}' may not be a union type.": {
|
||||
"category": "Error",
|
||||
"code": 2600
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
tests/cases/compiler/classImplementsClass6.ts(20,3): error TS2339: Property 'bar' does not exist on type 'C'.
|
||||
tests/cases/compiler/classImplementsClass6.ts(21,4): error TS2339: Property 'bar' does not exist on type 'C2'.
|
||||
tests/cases/compiler/classImplementsClass6.ts(21,4): error TS2576: Property 'bar' is a static member of type 'C2'
|
||||
|
||||
|
||||
==== tests/cases/compiler/classImplementsClass6.ts (2 errors) ====
|
||||
@ -27,4 +27,4 @@ tests/cases/compiler/classImplementsClass6.ts(21,4): error TS2339: Property 'bar
|
||||
!!! error TS2339: Property 'bar' does not exist on type 'C'.
|
||||
c2.bar(); // should error
|
||||
~~~
|
||||
!!! error TS2339: Property 'bar' does not exist on type 'C2'.
|
||||
!!! error TS2576: Property 'bar' is a static member of type 'C2'
|
||||
@ -1,5 +1,5 @@
|
||||
tests/cases/compiler/classSideInheritance1.ts(12,3): error TS2339: Property 'bar' does not exist on type 'A'.
|
||||
tests/cases/compiler/classSideInheritance1.ts(13,3): error TS2339: Property 'bar' does not exist on type 'C2'.
|
||||
tests/cases/compiler/classSideInheritance1.ts(12,3): error TS2576: Property 'bar' is a static member of type 'A'
|
||||
tests/cases/compiler/classSideInheritance1.ts(13,3): error TS2576: Property 'bar' is a static member of type 'C2'
|
||||
|
||||
|
||||
==== tests/cases/compiler/classSideInheritance1.ts (2 errors) ====
|
||||
@ -16,9 +16,9 @@ tests/cases/compiler/classSideInheritance1.ts(13,3): error TS2339: Property 'bar
|
||||
var c: C2;
|
||||
a.bar(); // static off an instance - should be an error
|
||||
~~~
|
||||
!!! error TS2339: Property 'bar' does not exist on type 'A'.
|
||||
!!! error TS2576: Property 'bar' is a static member of type 'A'
|
||||
c.bar(); // static off an instance - should be an error
|
||||
~~~
|
||||
!!! error TS2339: Property 'bar' does not exist on type 'C2'.
|
||||
!!! error TS2576: Property 'bar' is a static member of type 'C2'
|
||||
A.bar(); // valid
|
||||
C2.bar(); // valid
|
||||
@ -0,0 +1,28 @@
|
||||
tests/cases/compiler/classStaticPropertyAccess.ts(9,1): error TS2576: Property 'y' is a static member of type 'A'
|
||||
tests/cases/compiler/classStaticPropertyAccess.ts(10,3): error TS2576: Property 'y' is a static member of type 'A'
|
||||
tests/cases/compiler/classStaticPropertyAccess.ts(11,3): error TS2341: Property '_b' is private and only accessible within class 'A'.
|
||||
tests/cases/compiler/classStaticPropertyAccess.ts(12,3): error TS2339: Property 'a' does not exist on type 'typeof A'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/classStaticPropertyAccess.ts (4 errors) ====
|
||||
class A {
|
||||
public static x: number = 1;
|
||||
public static y: number = 1;
|
||||
private static _b: number = 2;
|
||||
}
|
||||
|
||||
const a = new A();
|
||||
|
||||
a['y'] // Error
|
||||
~~~~~~
|
||||
!!! error TS2576: Property 'y' is a static member of type 'A'
|
||||
a.y // Error
|
||||
~
|
||||
!!! error TS2576: Property 'y' is a static member of type 'A'
|
||||
A._b // Error
|
||||
~~
|
||||
!!! error TS2341: Property '_b' is private and only accessible within class 'A'.
|
||||
A.a
|
||||
~
|
||||
!!! error TS2339: Property 'a' does not exist on type 'typeof A'.
|
||||
|
||||
30
tests/baselines/reference/classStaticPropertyAccess.js
Normal file
30
tests/baselines/reference/classStaticPropertyAccess.js
Normal file
@ -0,0 +1,30 @@
|
||||
//// [classStaticPropertyAccess.ts]
|
||||
class A {
|
||||
public static x: number = 1;
|
||||
public static y: number = 1;
|
||||
private static _b: number = 2;
|
||||
}
|
||||
|
||||
const a = new A();
|
||||
|
||||
a['y'] // Error
|
||||
a.y // Error
|
||||
A._b // Error
|
||||
A.a
|
||||
|
||||
|
||||
//// [classStaticPropertyAccess.js]
|
||||
"use strict";
|
||||
var A = /** @class */ (function () {
|
||||
function A() {
|
||||
}
|
||||
A.x = 1;
|
||||
A.y = 1;
|
||||
A._b = 2;
|
||||
return A;
|
||||
}());
|
||||
var a = new A();
|
||||
a['y']; // Error
|
||||
a.y; // Error
|
||||
A._b; // Error
|
||||
A.a;
|
||||
32
tests/baselines/reference/classStaticPropertyAccess.symbols
Normal file
32
tests/baselines/reference/classStaticPropertyAccess.symbols
Normal file
@ -0,0 +1,32 @@
|
||||
=== tests/cases/compiler/classStaticPropertyAccess.ts ===
|
||||
class A {
|
||||
>A : Symbol(A, Decl(classStaticPropertyAccess.ts, 0, 0))
|
||||
|
||||
public static x: number = 1;
|
||||
>x : Symbol(A.x, Decl(classStaticPropertyAccess.ts, 0, 9))
|
||||
|
||||
public static y: number = 1;
|
||||
>y : Symbol(A.y, Decl(classStaticPropertyAccess.ts, 1, 32))
|
||||
|
||||
private static _b: number = 2;
|
||||
>_b : Symbol(A._b, Decl(classStaticPropertyAccess.ts, 2, 32))
|
||||
}
|
||||
|
||||
const a = new A();
|
||||
>a : Symbol(a, Decl(classStaticPropertyAccess.ts, 6, 5))
|
||||
>A : Symbol(A, Decl(classStaticPropertyAccess.ts, 0, 0))
|
||||
|
||||
a['y'] // Error
|
||||
>a : Symbol(a, Decl(classStaticPropertyAccess.ts, 6, 5))
|
||||
|
||||
a.y // Error
|
||||
>a : Symbol(a, Decl(classStaticPropertyAccess.ts, 6, 5))
|
||||
|
||||
A._b // Error
|
||||
>A._b : Symbol(A._b, Decl(classStaticPropertyAccess.ts, 2, 32))
|
||||
>A : Symbol(A, Decl(classStaticPropertyAccess.ts, 0, 0))
|
||||
>_b : Symbol(A._b, Decl(classStaticPropertyAccess.ts, 2, 32))
|
||||
|
||||
A.a
|
||||
>A : Symbol(A, Decl(classStaticPropertyAccess.ts, 0, 0))
|
||||
|
||||
42
tests/baselines/reference/classStaticPropertyAccess.types
Normal file
42
tests/baselines/reference/classStaticPropertyAccess.types
Normal file
@ -0,0 +1,42 @@
|
||||
=== tests/cases/compiler/classStaticPropertyAccess.ts ===
|
||||
class A {
|
||||
>A : A
|
||||
|
||||
public static x: number = 1;
|
||||
>x : number
|
||||
>1 : 1
|
||||
|
||||
public static y: number = 1;
|
||||
>y : number
|
||||
>1 : 1
|
||||
|
||||
private static _b: number = 2;
|
||||
>_b : number
|
||||
>2 : 2
|
||||
}
|
||||
|
||||
const a = new A();
|
||||
>a : A
|
||||
>new A() : A
|
||||
>A : typeof A
|
||||
|
||||
a['y'] // Error
|
||||
>a['y'] : any
|
||||
>a : A
|
||||
>'y' : "y"
|
||||
|
||||
a.y // Error
|
||||
>a.y : any
|
||||
>a : A
|
||||
>y : any
|
||||
|
||||
A._b // Error
|
||||
>A._b : number
|
||||
>A : typeof A
|
||||
>_b : number
|
||||
|
||||
A.a
|
||||
>A.a : any
|
||||
>A : typeof A
|
||||
>a : any
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
tests/cases/compiler/cloduleTest2.ts(4,13): error TS2554: Expected 1 arguments, but got 0.
|
||||
tests/cases/compiler/cloduleTest2.ts(10,13): error TS2554: Expected 1 arguments, but got 0.
|
||||
tests/cases/compiler/cloduleTest2.ts(18,7): error TS2339: Property 'bar' does not exist on type 'm3d'.
|
||||
tests/cases/compiler/cloduleTest2.ts(18,7): error TS2576: Property 'bar' is a static member of type 'm3d'
|
||||
tests/cases/compiler/cloduleTest2.ts(19,7): error TS2339: Property 'y' does not exist on type 'm3d'.
|
||||
tests/cases/compiler/cloduleTest2.ts(27,7): error TS2339: Property 'bar' does not exist on type 'm3d'.
|
||||
tests/cases/compiler/cloduleTest2.ts(27,7): error TS2576: Property 'bar' is a static member of type 'm3d'
|
||||
tests/cases/compiler/cloduleTest2.ts(28,7): error TS2339: Property 'y' does not exist on type 'm3d'.
|
||||
tests/cases/compiler/cloduleTest2.ts(33,9): error TS2554: Expected 1 arguments, but got 0.
|
||||
tests/cases/compiler/cloduleTest2.ts(36,10): error TS2554: Expected 1 arguments, but got 0.
|
||||
@ -32,7 +32,7 @@ tests/cases/compiler/cloduleTest2.ts(36,10): error TS2554: Expected 1 arguments,
|
||||
r.foo();
|
||||
r.bar(); // error
|
||||
~~~
|
||||
!!! error TS2339: Property 'bar' does not exist on type 'm3d'.
|
||||
!!! error TS2576: Property 'bar' is a static member of type 'm3d'
|
||||
r.y; // error
|
||||
~
|
||||
!!! error TS2339: Property 'y' does not exist on type 'm3d'.
|
||||
@ -45,7 +45,7 @@ tests/cases/compiler/cloduleTest2.ts(36,10): error TS2554: Expected 1 arguments,
|
||||
r.foo();
|
||||
r.bar(); // error
|
||||
~~~
|
||||
!!! error TS2339: Property 'bar' does not exist on type 'm3d'.
|
||||
!!! error TS2576: Property 'bar' is a static member of type 'm3d'
|
||||
r.y; // error
|
||||
~
|
||||
!!! error TS2339: Property 'y' does not exist on type 'm3d'.
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
tests/cases/compiler/staticMemberExportAccess.ts(14,35): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/compiler/staticMemberExportAccess.ts(17,18): error TS2339: Property 'bar' does not exist on type 'Sammy'.
|
||||
tests/cases/compiler/staticMemberExportAccess.ts(17,18): error TS2576: Property 'bar' is a static member of type 'Sammy'
|
||||
tests/cases/compiler/staticMemberExportAccess.ts(18,18): error TS2339: Property 'x' does not exist on type 'Sammy'.
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ tests/cases/compiler/staticMemberExportAccess.ts(18,18): error TS2339: Property
|
||||
var r2 = $.sammy.foo();
|
||||
var r3 = $.sammy.bar(); // error
|
||||
~~~
|
||||
!!! error TS2339: Property 'bar' does not exist on type 'Sammy'.
|
||||
!!! error TS2576: Property 'bar' is a static member of type 'Sammy'
|
||||
var r4 = $.sammy.x; // error
|
||||
~
|
||||
!!! error TS2339: Property 'x' does not exist on type 'Sammy'.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
tests/cases/compiler/staticOffOfInstance1.ts(3,10): error TS2339: Property 'Foo' does not exist on type 'List'.
|
||||
tests/cases/compiler/staticOffOfInstance1.ts(3,10): error TS2576: Property 'Foo' is a static member of type 'List'
|
||||
|
||||
|
||||
==== tests/cases/compiler/staticOffOfInstance1.ts (1 errors) ====
|
||||
@ -6,7 +6,7 @@ tests/cases/compiler/staticOffOfInstance1.ts(3,10): error TS2339: Property 'Foo'
|
||||
public Blah() {
|
||||
this.Foo();
|
||||
~~~
|
||||
!!! error TS2339: Property 'Foo' does not exist on type 'List'.
|
||||
!!! error TS2576: Property 'Foo' is a static member of type 'List'
|
||||
}
|
||||
public static Foo() {}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
tests/cases/compiler/staticOffOfInstance2.ts(3,14): error TS2339: Property 'Foo' does not exist on type 'List<T>'.
|
||||
tests/cases/compiler/staticOffOfInstance2.ts(3,14): error TS2576: Property 'Foo' is a static member of type 'List<T>'
|
||||
|
||||
|
||||
==== tests/cases/compiler/staticOffOfInstance2.ts (1 errors) ====
|
||||
@ -6,7 +6,7 @@ tests/cases/compiler/staticOffOfInstance2.ts(3,14): error TS2339: Property 'Foo'
|
||||
public Blah() {
|
||||
this.Foo(); // no error
|
||||
~~~
|
||||
!!! error TS2339: Property 'Foo' does not exist on type 'List<T>'.
|
||||
!!! error TS2576: Property 'Foo' is a static member of type 'List<T>'
|
||||
List.Foo();
|
||||
}
|
||||
public static Foo() { }
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(4,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
||||
tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(5,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
||||
tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(16,16): error TS2339: Property 'foo' does not exist on type 'C'.
|
||||
tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(16,16): error TS2576: Property 'foo' is a static member of type 'C'
|
||||
tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(17,16): error TS2339: Property 'bar' does not exist on type 'C'.
|
||||
tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(18,16): error TS2339: Property 'x' does not exist on type 'C'.
|
||||
tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(18,16): error TS2576: Property 'x' is a static member of type 'C'
|
||||
tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(24,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
||||
tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(25,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
||||
tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(27,21): error TS2302: Static members cannot reference class type parameters.
|
||||
tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(36,16): error TS2339: Property 'foo' does not exist on type 'C<number, string>'.
|
||||
tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(36,16): error TS2576: Property 'foo' is a static member of type 'C<number, string>'
|
||||
tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(37,16): error TS2339: Property 'bar' does not exist on type 'C<number, string>'.
|
||||
tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(38,16): error TS2339: Property 'x' does not exist on type 'C<number, string>'.
|
||||
tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(38,16): error TS2576: Property 'x' is a static member of type 'C<number, string>'
|
||||
|
||||
|
||||
==== tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts (11 errors) ====
|
||||
@ -33,13 +33,13 @@ tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.
|
||||
var r = c.fn();
|
||||
var r4 = c.foo; // error
|
||||
~~~
|
||||
!!! error TS2339: Property 'foo' does not exist on type 'C'.
|
||||
!!! error TS2576: Property 'foo' is a static member of type 'C'
|
||||
var r5 = c.bar; // error
|
||||
~~~
|
||||
!!! error TS2339: Property 'bar' does not exist on type 'C'.
|
||||
var r6 = c.x; // error
|
||||
~
|
||||
!!! error TS2339: Property 'x' does not exist on type 'C'.
|
||||
!!! error TS2576: Property 'x' is a static member of type 'C'
|
||||
}
|
||||
|
||||
module Generic {
|
||||
@ -65,11 +65,11 @@ tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.
|
||||
var r = c.fn();
|
||||
var r4 = c.foo; // error
|
||||
~~~
|
||||
!!! error TS2339: Property 'foo' does not exist on type 'C<number, string>'.
|
||||
!!! error TS2576: Property 'foo' is a static member of type 'C<number, string>'
|
||||
var r5 = c.bar; // error
|
||||
~~~
|
||||
!!! error TS2339: Property 'bar' does not exist on type 'C<number, string>'.
|
||||
var r6 = c.x; // error
|
||||
~
|
||||
!!! error TS2339: Property 'x' does not exist on type 'C<number, string>'.
|
||||
!!! error TS2576: Property 'x' is a static member of type 'C<number, string>'
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
tests/cases/compiler/superAccess.ts(9,24): error TS2339: Property 'S1' does not exist on type 'MyBase'.
|
||||
tests/cases/compiler/superAccess.ts(9,24): error TS2576: Property 'S1' is a static member of type 'MyBase'
|
||||
tests/cases/compiler/superAccess.ts(10,24): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
|
||||
tests/cases/compiler/superAccess.ts(11,24): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
|
||||
|
||||
@ -14,7 +14,7 @@ tests/cases/compiler/superAccess.ts(11,24): error TS2340: Only public and protec
|
||||
foo() {
|
||||
var l3 = super.S1; // Expected => Error: Only public instance methods of the base class are accessible via the 'super' keyword
|
||||
~~
|
||||
!!! error TS2339: Property 'S1' does not exist on type 'MyBase'.
|
||||
!!! error TS2576: Property 'S1' is a static member of type 'MyBase'
|
||||
var l4 = super.S2; // Expected => Error: Only public instance methods of the base class are accessible via the 'super' keyword
|
||||
~~
|
||||
!!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
|
||||
|
||||
@ -11,7 +11,7 @@ tests/cases/compiler/superAccess2.ts(11,59): error TS2336: 'super' cannot be ref
|
||||
tests/cases/compiler/superAccess2.ts(11,59): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
|
||||
tests/cases/compiler/superAccess2.ts(11,64): error TS1034: 'super' must be followed by an argument list or member access.
|
||||
tests/cases/compiler/superAccess2.ts(15,19): error TS1034: 'super' must be followed by an argument list or member access.
|
||||
tests/cases/compiler/superAccess2.ts(17,15): error TS2339: Property 'y' does not exist on type 'P'.
|
||||
tests/cases/compiler/superAccess2.ts(17,15): error TS2576: Property 'y' is a static member of type 'P'
|
||||
tests/cases/compiler/superAccess2.ts(20,26): error TS1034: 'super' must be followed by an argument list or member access.
|
||||
tests/cases/compiler/superAccess2.ts(21,15): error TS2339: Property 'x' does not exist on type 'typeof P'.
|
||||
|
||||
@ -61,7 +61,7 @@ tests/cases/compiler/superAccess2.ts(21,15): error TS2339: Property 'x' does not
|
||||
super.x();
|
||||
super.y(); // error
|
||||
~
|
||||
!!! error TS2339: Property 'y' does not exist on type 'P'.
|
||||
!!! error TS2576: Property 'y' is a static member of type 'P'
|
||||
}
|
||||
|
||||
static bar(zz = super) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
tests/cases/compiler/superPropertyAccess2.ts(3,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
||||
tests/cases/compiler/superPropertyAccess2.ts(13,15): error TS2339: Property 'x' does not exist on type 'typeof C'.
|
||||
tests/cases/compiler/superPropertyAccess2.ts(18,15): error TS2339: Property 'bar' does not exist on type 'C'.
|
||||
tests/cases/compiler/superPropertyAccess2.ts(18,15): error TS2576: Property 'bar' is a static member of type 'C'
|
||||
tests/cases/compiler/superPropertyAccess2.ts(19,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
|
||||
tests/cases/compiler/superPropertyAccess2.ts(22,23): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
||||
tests/cases/compiler/superPropertyAccess2.ts(24,15): error TS2339: Property 'x' does not exist on type 'typeof C'.
|
||||
@ -30,7 +30,7 @@ tests/cases/compiler/superPropertyAccess2.ts(24,15): error TS2339: Property 'x'
|
||||
super();
|
||||
super.bar(); // error
|
||||
~~~
|
||||
!!! error TS2339: Property 'bar' does not exist on type 'C'.
|
||||
!!! error TS2576: Property 'bar' is a static member of type 'C'
|
||||
super.x; // error
|
||||
~
|
||||
!!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
tests/cases/compiler/thisInOuterClassBody.ts(5,16): error TS2334: 'this' cannot be referenced in a static property initializer.
|
||||
tests/cases/compiler/thisInOuterClassBody.ts(12,22): error TS2339: Property 'y' does not exist on type 'Foo'.
|
||||
tests/cases/compiler/thisInOuterClassBody.ts(12,22): error TS2576: Property 'y' is a static member of type 'Foo'
|
||||
tests/cases/compiler/thisInOuterClassBody.ts(18,22): error TS2339: Property 'x' does not exist on type 'typeof Foo'.
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ tests/cases/compiler/thisInOuterClassBody.ts(18,22): error TS2339: Property 'x'
|
||||
var f = () => this.x; // 'this' should be type 'Foo' as well
|
||||
var p = this.y;
|
||||
~
|
||||
!!! error TS2339: Property 'y' does not exist on type 'Foo'.
|
||||
!!! error TS2576: Property 'y' is a static member of type 'Foo'
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
tests/cases/compiler/typeofClass.ts(8,4): error TS2339: Property 'bar' does not exist on type 'K'.
|
||||
tests/cases/compiler/typeofClass.ts(8,4): error TS2576: Property 'bar' is a static member of type 'K'
|
||||
tests/cases/compiler/typeofClass.ts(10,4): error TS2339: Property 'foo' does not exist on type 'typeof K'.
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ tests/cases/compiler/typeofClass.ts(10,4): error TS2339: Property 'foo' does not
|
||||
k1.foo;
|
||||
k1.bar;
|
||||
~~~
|
||||
!!! error TS2339: Property 'bar' does not exist on type 'K'.
|
||||
!!! error TS2576: Property 'bar' is a static member of type 'K'
|
||||
var k2: typeof K;
|
||||
k2.foo;
|
||||
~~~
|
||||
|
||||
15
tests/cases/compiler/classStaticPropertyAccess.ts
Normal file
15
tests/cases/compiler/classStaticPropertyAccess.ts
Normal file
@ -0,0 +1,15 @@
|
||||
// @strict: true
|
||||
// @target: ES5
|
||||
|
||||
class A {
|
||||
public static x: number = 1;
|
||||
public static y: number = 1;
|
||||
private static _b: number = 2;
|
||||
}
|
||||
|
||||
const a = new A();
|
||||
|
||||
a['y'] // Error
|
||||
a.y // Error
|
||||
A._b // Error
|
||||
A.a
|
||||
@ -1,5 +1,4 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
|
||||
@ -15,7 +14,6 @@
|
||||
// @Filename: f1.ts
|
||||
//// export class C {[|
|
||||
//// |]x: number;
|
||||
//// static y: string;
|
||||
//// }
|
||||
|
||||
verify.getAndApplyCodeFix(/*errorCode*/undefined, 0);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user