From 37b9a6bca4eea73222d317cfb383d4a8ebb7ec3d Mon Sep 17 00:00:00 2001 From: Alexander T Date: Mon, 6 Aug 2018 20:24:48 +0300 Subject: [PATCH] 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 --- src/compiler/checker.ts | 35 ++++++++++------ src/compiler/diagnosticMessages.json | 4 ++ .../classImplementsClass6.errors.txt | 4 +- .../classSideInheritance1.errors.txt | 8 ++-- .../classStaticPropertyAccess.errors.txt | 28 +++++++++++++ .../reference/classStaticPropertyAccess.js | 30 +++++++++++++ .../classStaticPropertyAccess.symbols | 32 ++++++++++++++ .../reference/classStaticPropertyAccess.types | 42 +++++++++++++++++++ .../reference/cloduleTest2.errors.txt | 8 ++-- .../staticMemberExportAccess.errors.txt | 4 +- .../reference/staticOffOfInstance1.errors.txt | 4 +- .../reference/staticOffOfInstance2.errors.txt | 4 +- .../staticPropertyNotInClassType.errors.txt | 16 +++---- .../reference/superAccess.errors.txt | 4 +- .../reference/superAccess2.errors.txt | 4 +- .../reference/superPropertyAccess2.errors.txt | 4 +- .../reference/thisInOuterClassBody.errors.txt | 4 +- .../reference/typeofClass.errors.txt | 4 +- .../compiler/classStaticPropertyAccess.ts | 15 +++++++ .../codeFixUndeclaredAcrossFiles1.ts | 2 - 20 files changed, 208 insertions(+), 48 deletions(-) create mode 100644 tests/baselines/reference/classStaticPropertyAccess.errors.txt create mode 100644 tests/baselines/reference/classStaticPropertyAccess.js create mode 100644 tests/baselines/reference/classStaticPropertyAccess.symbols create mode 100644 tests/baselines/reference/classStaticPropertyAccess.types create mode 100644 tests/cases/compiler/classStaticPropertyAccess.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e1391275b28..eaa6a2937cb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index babb48797b5..487fb334428 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -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 diff --git a/tests/baselines/reference/classImplementsClass6.errors.txt b/tests/baselines/reference/classImplementsClass6.errors.txt index 706f94c8fbb..a09ea501554 100644 --- a/tests/baselines/reference/classImplementsClass6.errors.txt +++ b/tests/baselines/reference/classImplementsClass6.errors.txt @@ -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'. \ No newline at end of file +!!! error TS2576: Property 'bar' is a static member of type 'C2' \ No newline at end of file diff --git a/tests/baselines/reference/classSideInheritance1.errors.txt b/tests/baselines/reference/classSideInheritance1.errors.txt index b1f02bac123..6598ccbfd5c 100644 --- a/tests/baselines/reference/classSideInheritance1.errors.txt +++ b/tests/baselines/reference/classSideInheritance1.errors.txt @@ -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 \ No newline at end of file diff --git a/tests/baselines/reference/classStaticPropertyAccess.errors.txt b/tests/baselines/reference/classStaticPropertyAccess.errors.txt new file mode 100644 index 00000000000..b54caae998e --- /dev/null +++ b/tests/baselines/reference/classStaticPropertyAccess.errors.txt @@ -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'. + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticPropertyAccess.js b/tests/baselines/reference/classStaticPropertyAccess.js new file mode 100644 index 00000000000..92753c6de0e --- /dev/null +++ b/tests/baselines/reference/classStaticPropertyAccess.js @@ -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; diff --git a/tests/baselines/reference/classStaticPropertyAccess.symbols b/tests/baselines/reference/classStaticPropertyAccess.symbols new file mode 100644 index 00000000000..a5854a6566c --- /dev/null +++ b/tests/baselines/reference/classStaticPropertyAccess.symbols @@ -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)) + diff --git a/tests/baselines/reference/classStaticPropertyAccess.types b/tests/baselines/reference/classStaticPropertyAccess.types new file mode 100644 index 00000000000..4736867dbd4 --- /dev/null +++ b/tests/baselines/reference/classStaticPropertyAccess.types @@ -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 + diff --git a/tests/baselines/reference/cloduleTest2.errors.txt b/tests/baselines/reference/cloduleTest2.errors.txt index 6a3c763ee58..ec780ba72a2 100644 --- a/tests/baselines/reference/cloduleTest2.errors.txt +++ b/tests/baselines/reference/cloduleTest2.errors.txt @@ -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'. diff --git a/tests/baselines/reference/staticMemberExportAccess.errors.txt b/tests/baselines/reference/staticMemberExportAccess.errors.txt index fb2485c99e6..71fe50d4809 100644 --- a/tests/baselines/reference/staticMemberExportAccess.errors.txt +++ b/tests/baselines/reference/staticMemberExportAccess.errors.txt @@ -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'. diff --git a/tests/baselines/reference/staticOffOfInstance1.errors.txt b/tests/baselines/reference/staticOffOfInstance1.errors.txt index 61063f3219a..0144643fb96 100644 --- a/tests/baselines/reference/staticOffOfInstance1.errors.txt +++ b/tests/baselines/reference/staticOffOfInstance1.errors.txt @@ -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() {} } \ No newline at end of file diff --git a/tests/baselines/reference/staticOffOfInstance2.errors.txt b/tests/baselines/reference/staticOffOfInstance2.errors.txt index ac22f18aae7..9b5202beb6e 100644 --- a/tests/baselines/reference/staticOffOfInstance2.errors.txt +++ b/tests/baselines/reference/staticOffOfInstance2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/staticOffOfInstance2.ts(3,14): error TS2339: Property 'Foo' does not exist on type 'List'. +tests/cases/compiler/staticOffOfInstance2.ts(3,14): error TS2576: Property 'Foo' is a static member of type 'List' ==== 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'. +!!! error TS2576: Property 'Foo' is a static member of type 'List' List.Foo(); } public static Foo() { } diff --git a/tests/baselines/reference/staticPropertyNotInClassType.errors.txt b/tests/baselines/reference/staticPropertyNotInClassType.errors.txt index 62f04b5c5fb..d37344605a1 100644 --- a/tests/baselines/reference/staticPropertyNotInClassType.errors.txt +++ b/tests/baselines/reference/staticPropertyNotInClassType.errors.txt @@ -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'. +tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(36,16): error TS2576: Property 'foo' is a static member of type 'C' tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(37,16): error TS2339: Property 'bar' does not exist on type 'C'. -tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(38,16): error TS2339: Property 'x' does not exist on type 'C'. +tests/cases/conformance/classes/members/classTypes/staticPropertyNotInClassType.ts(38,16): error TS2576: Property 'x' is a static member of type 'C' ==== 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'. +!!! 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' } \ No newline at end of file diff --git a/tests/baselines/reference/superAccess.errors.txt b/tests/baselines/reference/superAccess.errors.txt index f506bb9f136..76d1f326458 100644 --- a/tests/baselines/reference/superAccess.errors.txt +++ b/tests/baselines/reference/superAccess.errors.txt @@ -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. diff --git a/tests/baselines/reference/superAccess2.errors.txt b/tests/baselines/reference/superAccess2.errors.txt index edcd4031c47..3ba682b3145 100644 --- a/tests/baselines/reference/superAccess2.errors.txt +++ b/tests/baselines/reference/superAccess2.errors.txt @@ -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) { diff --git a/tests/baselines/reference/superPropertyAccess2.errors.txt b/tests/baselines/reference/superPropertyAccess2.errors.txt index 2512ad91fae..1ac6fa7b94b 100644 --- a/tests/baselines/reference/superPropertyAccess2.errors.txt +++ b/tests/baselines/reference/superPropertyAccess2.errors.txt @@ -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. diff --git a/tests/baselines/reference/thisInOuterClassBody.errors.txt b/tests/baselines/reference/thisInOuterClassBody.errors.txt index 9b358d43ef6..2e67739c203 100644 --- a/tests/baselines/reference/thisInOuterClassBody.errors.txt +++ b/tests/baselines/reference/thisInOuterClassBody.errors.txt @@ -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; } diff --git a/tests/baselines/reference/typeofClass.errors.txt b/tests/baselines/reference/typeofClass.errors.txt index c427b1aaa74..7266f2bea46 100644 --- a/tests/baselines/reference/typeofClass.errors.txt +++ b/tests/baselines/reference/typeofClass.errors.txt @@ -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; ~~~ diff --git a/tests/cases/compiler/classStaticPropertyAccess.ts b/tests/cases/compiler/classStaticPropertyAccess.ts new file mode 100644 index 00000000000..e5cc8dfb0f2 --- /dev/null +++ b/tests/cases/compiler/classStaticPropertyAccess.ts @@ -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 diff --git a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts index 8e816b7937f..8f775d5158e 100644 --- a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts +++ b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts @@ -1,5 +1,4 @@ /// - // @allowJs: true // @checkJs: true @@ -15,7 +14,6 @@ // @Filename: f1.ts //// export class C {[| //// |]x: number; -//// static y: string; //// } verify.getAndApplyCodeFix(/*errorCode*/undefined, 0);