Skip to content

Commit cfa29ae

Browse files
committed
Merge branch 'master' into fixCircularReturnType
# Conflicts: # src/compiler/diagnosticMessages.json
2 parents 6a17f4d + 37b9a6b commit cfa29ae

22 files changed

+217
-57
lines changed

src/compiler/checker.ts

+23-12
Original file line numberDiff line numberDiff line change
@@ -3322,7 +3322,6 @@ namespace ts {
33223322
// Anonymous types without a symbol are never circular.
33233323
return createTypeNodeFromObjectType(type);
33243324
}
3325-
33263325
function shouldWriteTypeOfFunctionSymbol() {
33273326
const isStaticMethodSymbol = !!(symbol.flags & SymbolFlags.Method) && // typeof static method
33283327
some(symbol.declarations, declaration => hasModifier(declaration, ModifierFlags.Static));
@@ -9161,7 +9160,10 @@ namespace ts {
91619160
}
91629161
if (accessExpression && !isConstEnumObjectType(objectType)) {
91639162
if (noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors) {
9164-
if (getIndexTypeOfType(objectType, IndexKind.Number)) {
9163+
if (propName !== undefined && typeHasStaticProperty(propName, objectType)) {
9164+
error(accessExpression, Diagnostics.Property_0_is_a_static_member_of_type_1, propName as string, typeToString(objectType));
9165+
}
9166+
else if (getIndexTypeOfType(objectType, IndexKind.Number)) {
91659167
error(accessExpression.argumentExpression, Diagnostics.Element_implicitly_has_an_any_type_because_index_expression_is_not_of_type_number);
91669168
}
91679169
else {
@@ -18050,29 +18052,38 @@ namespace ts {
1805018052
}
1805118053
}
1805218054
}
18053-
const promisedType = getPromisedTypeOfPromise(containingType);
18054-
if (promisedType && getPropertyOfType(promisedType, propNode.escapedText)) {
18055-
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await, declarationNameToString(propNode), typeToString(containingType));
18055+
if (typeHasStaticProperty(propNode.escapedText, containingType)) {
18056+
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_is_a_static_member_of_type_1, declarationNameToString(propNode), typeToString(containingType));
1805618057
}
1805718058
else {
18058-
const suggestion = getSuggestedSymbolForNonexistentProperty(propNode, containingType);
18059-
if (suggestion !== undefined) {
18060-
const suggestedName = symbolName(suggestion);
18061-
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, declarationNameToString(propNode), typeToString(containingType), suggestedName);
18062-
relatedInfo = suggestion.valueDeclaration && createDiagnosticForNode(suggestion.valueDeclaration, Diagnostics._0_is_declared_here, suggestedName);
18059+
const promisedType = getPromisedTypeOfPromise(containingType);
18060+
if (promisedType && getPropertyOfType(promisedType, propNode.escapedText)) {
18061+
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await, declarationNameToString(propNode), typeToString(containingType));
1806318062
}
1806418063
else {
18065-
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
18064+
const suggestion = getSuggestedSymbolForNonexistentProperty(propNode, containingType);
18065+
if (suggestion !== undefined) {
18066+
const suggestedName = symbolName(suggestion);
18067+
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, declarationNameToString(propNode), typeToString(containingType), suggestedName);
18068+
relatedInfo = suggestion.valueDeclaration && createDiagnosticForNode(suggestion.valueDeclaration, Diagnostics._0_is_declared_here, suggestedName);
18069+
}
18070+
else {
18071+
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
18072+
}
1806618073
}
1806718074
}
18068-
1806918075
const resultDiagnostic = createDiagnosticForNodeFromMessageChain(propNode, errorInfo);
1807018076
if (relatedInfo) {
1807118077
addRelatedInfo(resultDiagnostic, relatedInfo);
1807218078
}
1807318079
diagnostics.add(resultDiagnostic);
1807418080
}
1807518081

18082+
function typeHasStaticProperty(propName: __String, containingType: Type): boolean {
18083+
const prop = containingType.symbol && getPropertyOfType(getTypeOfSymbol(containingType.symbol), propName);
18084+
return prop !== undefined && prop.valueDeclaration && hasModifier(prop.valueDeclaration, ModifierFlags.Static);
18085+
}
18086+
1807618087
function getSuggestedSymbolForNonexistentProperty(name: Identifier | string, containingType: Type): Symbol | undefined {
1807718088
return getSpellingSuggestionForName(isString(name) ? name : idText(name), getPropertiesOfType(containingType), SymbolFlags.Value);
1807818089
}

src/compiler/diagnosticMessages.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -2064,10 +2064,14 @@
20642064
"category": "Error",
20652065
"code": 2575
20662066
},
2067-
"Return type annotation circularly references itself.": {
2067+
"Property '{0}' is a static member of type '{1}'": {
20682068
"category": "Error",
20692069
"code": 2576
20702070
},
2071+
"Return type annotation circularly references itself.": {
2072+
"category": "Error",
2073+
"code": 2577
2074+
},
20712075
"JSX element attributes type '{0}' may not be a union type.": {
20722076
"category": "Error",
20732077
"code": 2600

tests/baselines/reference/circularTypeofWithVarOrFunc.errors.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarO
22
tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts(2,5): error TS2502: 'varOfAliasedType1' is referenced directly or indirectly in its own type annotation.
33
tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts(4,5): error TS2502: 'varOfAliasedType2' is referenced directly or indirectly in its own type annotation.
44
tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts(5,6): error TS2456: Type alias 'typeAlias2' circularly references itself.
5-
tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts(7,18): error TS2576: Return type annotation circularly references itself.
5+
tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts(7,18): error TS2577: Return type annotation circularly references itself.
66
tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts(9,6): error TS2456: Type alias 'typeAlias3' circularly references itself.
77
tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts(18,6): error TS2456: Type alias 'R' circularly references itself.
8-
tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts(19,29): error TS2576: Return type annotation circularly references itself.
8+
tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts(19,29): error TS2577: Return type annotation circularly references itself.
99
tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts(25,6): error TS2456: Type alias 'R2' circularly references itself.
10-
tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts(26,15): error TS2576: Return type annotation circularly references itself.
10+
tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts(26,15): error TS2577: Return type annotation circularly references itself.
1111

1212

1313
==== tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts (10 errors) ====
@@ -27,7 +27,7 @@ tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarO
2727

2828
function func(): typeAlias3 { return null; }
2929
~~~~~~~~~~
30-
!!! error TS2576: Return type annotation circularly references itself.
30+
!!! error TS2577: Return type annotation circularly references itself.
3131
var varOfAliasedType3 = func();
3232
type typeAlias3 = typeof varOfAliasedType3;
3333
~~~~~~~~~~
@@ -45,7 +45,7 @@ tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarO
4545
!!! error TS2456: Type alias 'R' circularly references itself.
4646
function mul(input: Input): R {
4747
~
48-
!!! error TS2576: Return type annotation circularly references itself.
48+
!!! error TS2577: Return type annotation circularly references itself.
4949
return input.a * input.b;
5050
}
5151

@@ -56,5 +56,5 @@ tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarO
5656
!!! error TS2456: Type alias 'R2' circularly references itself.
5757
function f(): R2 { return 0; }
5858
~~
59-
!!! error TS2576: Return type annotation circularly references itself.
59+
!!! error TS2577: Return type annotation circularly references itself.
6060

tests/baselines/reference/classImplementsClass6.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/compiler/classImplementsClass6.ts(20,3): error TS2339: Property 'bar' does not exist on type 'C'.
2-
tests/cases/compiler/classImplementsClass6.ts(21,4): error TS2339: Property 'bar' does not exist on type 'C2'.
2+
tests/cases/compiler/classImplementsClass6.ts(21,4): error TS2576: Property 'bar' is a static member of type 'C2'
33

44

55
==== tests/cases/compiler/classImplementsClass6.ts (2 errors) ====
@@ -27,4 +27,4 @@ tests/cases/compiler/classImplementsClass6.ts(21,4): error TS2339: Property 'bar
2727
!!! error TS2339: Property 'bar' does not exist on type 'C'.
2828
c2.bar(); // should error
2929
~~~
30-
!!! error TS2339: Property 'bar' does not exist on type 'C2'.
30+
!!! error TS2576: Property 'bar' is a static member of type 'C2'

tests/baselines/reference/classSideInheritance1.errors.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tests/cases/compiler/classSideInheritance1.ts(12,3): error TS2339: Property 'bar' does not exist on type 'A'.
2-
tests/cases/compiler/classSideInheritance1.ts(13,3): error TS2339: Property 'bar' does not exist on type 'C2'.
1+
tests/cases/compiler/classSideInheritance1.ts(12,3): error TS2576: Property 'bar' is a static member of type 'A'
2+
tests/cases/compiler/classSideInheritance1.ts(13,3): error TS2576: Property 'bar' is a static member of type 'C2'
33

44

55
==== tests/cases/compiler/classSideInheritance1.ts (2 errors) ====
@@ -16,9 +16,9 @@ tests/cases/compiler/classSideInheritance1.ts(13,3): error TS2339: Property 'bar
1616
var c: C2;
1717
a.bar(); // static off an instance - should be an error
1818
~~~
19-
!!! error TS2339: Property 'bar' does not exist on type 'A'.
19+
!!! error TS2576: Property 'bar' is a static member of type 'A'
2020
c.bar(); // static off an instance - should be an error
2121
~~~
22-
!!! error TS2339: Property 'bar' does not exist on type 'C2'.
22+
!!! error TS2576: Property 'bar' is a static member of type 'C2'
2323
A.bar(); // valid
2424
C2.bar(); // valid
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
tests/cases/compiler/classStaticPropertyAccess.ts(9,1): error TS2576: Property 'y' is a static member of type 'A'
2+
tests/cases/compiler/classStaticPropertyAccess.ts(10,3): error TS2576: Property 'y' is a static member of type 'A'
3+
tests/cases/compiler/classStaticPropertyAccess.ts(11,3): error TS2341: Property '_b' is private and only accessible within class 'A'.
4+
tests/cases/compiler/classStaticPropertyAccess.ts(12,3): error TS2339: Property 'a' does not exist on type 'typeof A'.
5+
6+
7+
==== tests/cases/compiler/classStaticPropertyAccess.ts (4 errors) ====
8+
class A {
9+
public static x: number = 1;
10+
public static y: number = 1;
11+
private static _b: number = 2;
12+
}
13+
14+
const a = new A();
15+
16+
a['y'] // Error
17+
~~~~~~
18+
!!! error TS2576: Property 'y' is a static member of type 'A'
19+
a.y // Error
20+
~
21+
!!! error TS2576: Property 'y' is a static member of type 'A'
22+
A._b // Error
23+
~~
24+
!!! error TS2341: Property '_b' is private and only accessible within class 'A'.
25+
A.a
26+
~
27+
!!! error TS2339: Property 'a' does not exist on type 'typeof A'.
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//// [classStaticPropertyAccess.ts]
2+
class A {
3+
public static x: number = 1;
4+
public static y: number = 1;
5+
private static _b: number = 2;
6+
}
7+
8+
const a = new A();
9+
10+
a['y'] // Error
11+
a.y // Error
12+
A._b // Error
13+
A.a
14+
15+
16+
//// [classStaticPropertyAccess.js]
17+
"use strict";
18+
var A = /** @class */ (function () {
19+
function A() {
20+
}
21+
A.x = 1;
22+
A.y = 1;
23+
A._b = 2;
24+
return A;
25+
}());
26+
var a = new A();
27+
a['y']; // Error
28+
a.y; // Error
29+
A._b; // Error
30+
A.a;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
=== tests/cases/compiler/classStaticPropertyAccess.ts ===
2+
class A {
3+
>A : Symbol(A, Decl(classStaticPropertyAccess.ts, 0, 0))
4+
5+
public static x: number = 1;
6+
>x : Symbol(A.x, Decl(classStaticPropertyAccess.ts, 0, 9))
7+
8+
public static y: number = 1;
9+
>y : Symbol(A.y, Decl(classStaticPropertyAccess.ts, 1, 32))
10+
11+
private static _b: number = 2;
12+
>_b : Symbol(A._b, Decl(classStaticPropertyAccess.ts, 2, 32))
13+
}
14+
15+
const a = new A();
16+
>a : Symbol(a, Decl(classStaticPropertyAccess.ts, 6, 5))
17+
>A : Symbol(A, Decl(classStaticPropertyAccess.ts, 0, 0))
18+
19+
a['y'] // Error
20+
>a : Symbol(a, Decl(classStaticPropertyAccess.ts, 6, 5))
21+
22+
a.y // Error
23+
>a : Symbol(a, Decl(classStaticPropertyAccess.ts, 6, 5))
24+
25+
A._b // Error
26+
>A._b : Symbol(A._b, Decl(classStaticPropertyAccess.ts, 2, 32))
27+
>A : Symbol(A, Decl(classStaticPropertyAccess.ts, 0, 0))
28+
>_b : Symbol(A._b, Decl(classStaticPropertyAccess.ts, 2, 32))
29+
30+
A.a
31+
>A : Symbol(A, Decl(classStaticPropertyAccess.ts, 0, 0))
32+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
=== tests/cases/compiler/classStaticPropertyAccess.ts ===
2+
class A {
3+
>A : A
4+
5+
public static x: number = 1;
6+
>x : number
7+
>1 : 1
8+
9+
public static y: number = 1;
10+
>y : number
11+
>1 : 1
12+
13+
private static _b: number = 2;
14+
>_b : number
15+
>2 : 2
16+
}
17+
18+
const a = new A();
19+
>a : A
20+
>new A() : A
21+
>A : typeof A
22+
23+
a['y'] // Error
24+
>a['y'] : any
25+
>a : A
26+
>'y' : "y"
27+
28+
a.y // Error
29+
>a.y : any
30+
>a : A
31+
>y : any
32+
33+
A._b // Error
34+
>A._b : number
35+
>A : typeof A
36+
>_b : number
37+
38+
A.a
39+
>A.a : any
40+
>A : typeof A
41+
>a : any
42+

tests/baselines/reference/cloduleTest2.errors.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
tests/cases/compiler/cloduleTest2.ts(4,13): error TS2554: Expected 1 arguments, but got 0.
22
tests/cases/compiler/cloduleTest2.ts(10,13): error TS2554: Expected 1 arguments, but got 0.
3-
tests/cases/compiler/cloduleTest2.ts(18,7): error TS2339: Property 'bar' does not exist on type 'm3d'.
3+
tests/cases/compiler/cloduleTest2.ts(18,7): error TS2576: Property 'bar' is a static member of type 'm3d'
44
tests/cases/compiler/cloduleTest2.ts(19,7): error TS2339: Property 'y' does not exist on type 'm3d'.
5-
tests/cases/compiler/cloduleTest2.ts(27,7): error TS2339: Property 'bar' does not exist on type 'm3d'.
5+
tests/cases/compiler/cloduleTest2.ts(27,7): error TS2576: Property 'bar' is a static member of type 'm3d'
66
tests/cases/compiler/cloduleTest2.ts(28,7): error TS2339: Property 'y' does not exist on type 'm3d'.
77
tests/cases/compiler/cloduleTest2.ts(33,9): error TS2554: Expected 1 arguments, but got 0.
88
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,
3232
r.foo();
3333
r.bar(); // error
3434
~~~
35-
!!! error TS2339: Property 'bar' does not exist on type 'm3d'.
35+
!!! error TS2576: Property 'bar' is a static member of type 'm3d'
3636
r.y; // error
3737
~
3838
!!! 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,
4545
r.foo();
4646
r.bar(); // error
4747
~~~
48-
!!! error TS2339: Property 'bar' does not exist on type 'm3d'.
48+
!!! error TS2576: Property 'bar' is a static member of type 'm3d'
4949
r.y; // error
5050
~
5151
!!! error TS2339: Property 'y' does not exist on type 'm3d'.

tests/baselines/reference/recursiveResolveTypeMembers.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/recursiveResolveTypeMembers.ts(4,49): error TS2576: Return type annotation circularly references itself.
1+
tests/cases/compiler/recursiveResolveTypeMembers.ts(4,49): error TS2577: Return type annotation circularly references itself.
22
tests/cases/compiler/recursiveResolveTypeMembers.ts(4,58): error TS2304: Cannot find name 'H'.
33
tests/cases/compiler/recursiveResolveTypeMembers.ts(4,62): error TS2574: A rest element type must be an array type.
44
tests/cases/compiler/recursiveResolveTypeMembers.ts(4,79): error TS2304: Cannot find name 'R'.
@@ -10,7 +10,7 @@ tests/cases/compiler/recursiveResolveTypeMembers.ts(4,79): error TS2304: Cannot
1010
type PromisedTuple<L extends any[], U = (...args: L) => void> =
1111
U extends (h: infer H, ...args: infer R) => [Promise<H>, ...PromisedTuple<R>] ? [] : []
1212
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13-
!!! error TS2576: Return type annotation circularly references itself.
13+
!!! error TS2577: Return type annotation circularly references itself.
1414
~
1515
!!! error TS2304: Cannot find name 'H'.
1616
~~~~~~~~~~~~~~~~~~~

tests/baselines/reference/staticMemberExportAccess.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/compiler/staticMemberExportAccess.ts(14,35): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
2-
tests/cases/compiler/staticMemberExportAccess.ts(17,18): error TS2339: Property 'bar' does not exist on type 'Sammy'.
2+
tests/cases/compiler/staticMemberExportAccess.ts(17,18): error TS2576: Property 'bar' is a static member of type 'Sammy'
33
tests/cases/compiler/staticMemberExportAccess.ts(18,18): error TS2339: Property 'x' does not exist on type 'Sammy'.
44

55

@@ -24,7 +24,7 @@ tests/cases/compiler/staticMemberExportAccess.ts(18,18): error TS2339: Property
2424
var r2 = $.sammy.foo();
2525
var r3 = $.sammy.bar(); // error
2626
~~~
27-
!!! error TS2339: Property 'bar' does not exist on type 'Sammy'.
27+
!!! error TS2576: Property 'bar' is a static member of type 'Sammy'
2828
var r4 = $.sammy.x; // error
2929
~
3030
!!! error TS2339: Property 'x' does not exist on type 'Sammy'.
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
tests/cases/compiler/staticOffOfInstance1.ts(3,10): error TS2339: Property 'Foo' does not exist on type 'List'.
1+
tests/cases/compiler/staticOffOfInstance1.ts(3,10): error TS2576: Property 'Foo' is a static member of type 'List'
22

33

44
==== tests/cases/compiler/staticOffOfInstance1.ts (1 errors) ====
55
class List {
66
public Blah() {
77
this.Foo();
88
~~~
9-
!!! error TS2339: Property 'Foo' does not exist on type 'List'.
9+
!!! error TS2576: Property 'Foo' is a static member of type 'List'
1010
}
1111
public static Foo() {}
1212
}

tests/baselines/reference/staticOffOfInstance2.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
tests/cases/compiler/staticOffOfInstance2.ts(3,14): error TS2339: Property 'Foo' does not exist on type 'List<T>'.
1+
tests/cases/compiler/staticOffOfInstance2.ts(3,14): error TS2576: Property 'Foo' is a static member of type 'List<T>'
22

33

44
==== tests/cases/compiler/staticOffOfInstance2.ts (1 errors) ====
55
class List<T> {
66
public Blah() {
77
this.Foo(); // no error
88
~~~
9-
!!! error TS2339: Property 'Foo' does not exist on type 'List<T>'.
9+
!!! error TS2576: Property 'Foo' is a static member of type 'List<T>'
1010
List.Foo();
1111
}
1212
public static Foo() { }

0 commit comments

Comments
 (0)