Skip to content

Commit 5be8f1f

Browse files
authored
Better handling of circular JS containers in getTypeOfVariableOrParameterOrProperty (microsoft#24732)
* avoid circularity in getTypeOfVariableOrParameterOrProperty Modify getTypeOfVariableOrParameterOrProperty to get the type of the variable declaration before widening it. This essentially avoids some circularities by (1) setting the type of the variable declaration to the unwidened type (2) updating the type of the variable declaration to the widened one. You will still get a circular noImplicitAny in (1), for expressions that actually are circular, but not in (2), for the containers of things that are not themselves circular. * Stop checking js init object literals via checkObjectLiteral * checkBinaryExpression: new code for special assignments * Chained lookup for js initializer type * Check for JS-specific types only once Also make sure to respect the type annotation if there is one. * Accept API changes
1 parent 8ba5fb9 commit 5be8f1f

File tree

45 files changed

+1231
-999
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1231
-999
lines changed

src/compiler/binder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2514,11 +2514,12 @@ namespace ts {
25142514
return true;
25152515
}
25162516
const node = symbol.valueDeclaration;
2517-
const init = !node ? undefined :
2517+
let init = !node ? undefined :
25182518
isVariableDeclaration(node) ? node.initializer :
25192519
isBinaryExpression(node) ? node.right :
25202520
isPropertyAccessExpression(node) && isBinaryExpression(node.parent) ? node.parent.right :
25212521
undefined;
2522+
init = init && getRightMostAssignedExpression(init);
25222523
if (init) {
25232524
const isPrototypeAssignment = isPrototypeAccess(isVariableDeclaration(node) ? node.name : isBinaryExpression(node) ? node.left : node);
25242525
return !!getJavascriptInitializer(isBinaryExpression(init) && init.operatorToken.kind === SyntaxKind.BarBarToken ? init.right : init, isPrototypeAssignment);

src/compiler/checker.ts

Lines changed: 128 additions & 78 deletions
Large diffs are not rendered by default.

src/parser/utilities.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,12 @@ namespace ts {
17611761
return node.initializer;
17621762
}
17631763

1764+
/** Get the declaration initializer when it is container-like (See getJavascriptInitializer). */
1765+
export function getDeclaredJavascriptInitializer(node: HasExpressionInitializer) {
1766+
const init = getEffectiveInitializer(node);
1767+
return init && getJavascriptInitializer(init, isPrototypeAccess(node.name));
1768+
}
1769+
17641770
/**
17651771
* Get the assignment 'initializer' -- the righthand side-- when the initializer is container-like (See getJavascriptInitializer).
17661772
* We treat the right hand side of assignments with container-like initalizers as declarations.

tests/baselines/reference/APISample_Watch.errors.txt

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,65 @@
11
typescript_standalone.d.ts(21,28): error TS1005: ';' expected.
22
typescript_standalone.d.ts(21,41): error TS1005: ';' expected.
3-
typescript_standalone.d.ts(8910,28): error TS1005: ';' expected.
4-
typescript_standalone.d.ts(8910,42): error TS1005: ';' expected.
5-
typescript_standalone.d.ts(9170,28): error TS1005: ';' expected.
6-
typescript_standalone.d.ts(9170,46): error TS1005: ';' expected.
7-
typescript_standalone.d.ts(9520,28): error TS1005: ';' expected.
8-
typescript_standalone.d.ts(9520,36): error TS1005: ';' expected.
9-
typescript_standalone.d.ts(9544,28): error TS1005: ';' expected.
10-
typescript_standalone.d.ts(9544,36): error TS1005: ';' expected.
11-
typescript_standalone.d.ts(9631,28): error TS1005: ';' expected.
12-
typescript_standalone.d.ts(9631,38): error TS1005: ';' expected.
13-
typescript_standalone.d.ts(10796,28): error TS1005: ';' expected.
14-
typescript_standalone.d.ts(10796,57): error TS1005: ';' expected.
15-
typescript_standalone.d.ts(10807,28): error TS1005: ';' expected.
16-
typescript_standalone.d.ts(10807,41): error TS1005: ';' expected.
17-
typescript_standalone.d.ts(10817,28): error TS1005: ';' expected.
18-
typescript_standalone.d.ts(10817,48): error TS1005: ';' expected.
19-
typescript_standalone.d.ts(10892,28): error TS1005: ';' expected.
20-
typescript_standalone.d.ts(10892,47): error TS1005: ';' expected.
21-
typescript_standalone.d.ts(10949,28): error TS1005: ';' expected.
22-
typescript_standalone.d.ts(10949,47): error TS1005: ';' expected.
23-
typescript_standalone.d.ts(11003,28): error TS1005: ';' expected.
24-
typescript_standalone.d.ts(11003,52): error TS1005: ';' expected.
25-
typescript_standalone.d.ts(11023,28): error TS1005: ';' expected.
26-
typescript_standalone.d.ts(11023,44): error TS1005: ';' expected.
27-
typescript_standalone.d.ts(11033,28): error TS1005: ';' expected.
28-
typescript_standalone.d.ts(11033,35): error TS1005: ';' expected.
29-
typescript_standalone.d.ts(11067,28): error TS1005: ';' expected.
30-
typescript_standalone.d.ts(11067,40): error TS1005: ';' expected.
31-
typescript_standalone.d.ts(11070,28): error TS1005: ';' expected.
32-
typescript_standalone.d.ts(11070,43): error TS1005: ';' expected.
33-
typescript_standalone.d.ts(11074,28): error TS1005: ';' expected.
34-
typescript_standalone.d.ts(11074,45): error TS1005: ';' expected.
35-
typescript_standalone.d.ts(11092,28): error TS1005: ';' expected.
36-
typescript_standalone.d.ts(11092,56): error TS1005: ';' expected.
37-
typescript_standalone.d.ts(11118,28): error TS1005: ';' expected.
38-
typescript_standalone.d.ts(11118,36): error TS1005: ';' expected.
39-
typescript_standalone.d.ts(11121,28): error TS1005: ';' expected.
40-
typescript_standalone.d.ts(11121,43): error TS1005: ';' expected.
41-
typescript_standalone.d.ts(11133,28): error TS1005: ';' expected.
42-
typescript_standalone.d.ts(11133,43): error TS1005: ';' expected.
43-
typescript_standalone.d.ts(11163,28): error TS1005: ';' expected.
44-
typescript_standalone.d.ts(11163,40): error TS1005: ';' expected.
45-
typescript_standalone.d.ts(11197,28): error TS1005: ';' expected.
46-
typescript_standalone.d.ts(11197,40): error TS1005: ';' expected.
47-
typescript_standalone.d.ts(11208,28): error TS1005: ';' expected.
48-
typescript_standalone.d.ts(11208,40): error TS1005: ';' expected.
49-
typescript_standalone.d.ts(11232,28): error TS1005: ';' expected.
50-
typescript_standalone.d.ts(11232,40): error TS1005: ';' expected.
51-
typescript_standalone.d.ts(11240,28): error TS1005: ';' expected.
52-
typescript_standalone.d.ts(11240,40): error TS1005: ';' expected.
53-
typescript_standalone.d.ts(11244,28): error TS1005: ';' expected.
54-
typescript_standalone.d.ts(11244,40): error TS1005: ';' expected.
55-
typescript_standalone.d.ts(11274,28): error TS1005: ';' expected.
56-
typescript_standalone.d.ts(11274,40): error TS1005: ';' expected.
57-
typescript_standalone.d.ts(11317,28): error TS1005: ';' expected.
58-
typescript_standalone.d.ts(11317,41): error TS1005: ';' expected.
59-
typescript_standalone.d.ts(11504,28): error TS1005: ';' expected.
60-
typescript_standalone.d.ts(11504,37): error TS1005: ';' expected.
3+
typescript_standalone.d.ts(8912,28): error TS1005: ';' expected.
4+
typescript_standalone.d.ts(8912,42): error TS1005: ';' expected.
5+
typescript_standalone.d.ts(9172,28): error TS1005: ';' expected.
6+
typescript_standalone.d.ts(9172,46): error TS1005: ';' expected.
7+
typescript_standalone.d.ts(9522,28): error TS1005: ';' expected.
8+
typescript_standalone.d.ts(9522,36): error TS1005: ';' expected.
9+
typescript_standalone.d.ts(9546,28): error TS1005: ';' expected.
10+
typescript_standalone.d.ts(9546,36): error TS1005: ';' expected.
11+
typescript_standalone.d.ts(9633,28): error TS1005: ';' expected.
12+
typescript_standalone.d.ts(9633,38): error TS1005: ';' expected.
13+
typescript_standalone.d.ts(10798,28): error TS1005: ';' expected.
14+
typescript_standalone.d.ts(10798,57): error TS1005: ';' expected.
15+
typescript_standalone.d.ts(10809,28): error TS1005: ';' expected.
16+
typescript_standalone.d.ts(10809,41): error TS1005: ';' expected.
17+
typescript_standalone.d.ts(10819,28): error TS1005: ';' expected.
18+
typescript_standalone.d.ts(10819,48): error TS1005: ';' expected.
19+
typescript_standalone.d.ts(10894,28): error TS1005: ';' expected.
20+
typescript_standalone.d.ts(10894,47): error TS1005: ';' expected.
21+
typescript_standalone.d.ts(10951,28): error TS1005: ';' expected.
22+
typescript_standalone.d.ts(10951,47): error TS1005: ';' expected.
23+
typescript_standalone.d.ts(11005,28): error TS1005: ';' expected.
24+
typescript_standalone.d.ts(11005,52): error TS1005: ';' expected.
25+
typescript_standalone.d.ts(11025,28): error TS1005: ';' expected.
26+
typescript_standalone.d.ts(11025,44): error TS1005: ';' expected.
27+
typescript_standalone.d.ts(11035,28): error TS1005: ';' expected.
28+
typescript_standalone.d.ts(11035,35): error TS1005: ';' expected.
29+
typescript_standalone.d.ts(11069,28): error TS1005: ';' expected.
30+
typescript_standalone.d.ts(11069,40): error TS1005: ';' expected.
31+
typescript_standalone.d.ts(11072,28): error TS1005: ';' expected.
32+
typescript_standalone.d.ts(11072,43): error TS1005: ';' expected.
33+
typescript_standalone.d.ts(11076,28): error TS1005: ';' expected.
34+
typescript_standalone.d.ts(11076,45): error TS1005: ';' expected.
35+
typescript_standalone.d.ts(11094,28): error TS1005: ';' expected.
36+
typescript_standalone.d.ts(11094,56): error TS1005: ';' expected.
37+
typescript_standalone.d.ts(11120,28): error TS1005: ';' expected.
38+
typescript_standalone.d.ts(11120,36): error TS1005: ';' expected.
39+
typescript_standalone.d.ts(11123,28): error TS1005: ';' expected.
40+
typescript_standalone.d.ts(11123,43): error TS1005: ';' expected.
41+
typescript_standalone.d.ts(11135,28): error TS1005: ';' expected.
42+
typescript_standalone.d.ts(11135,43): error TS1005: ';' expected.
43+
typescript_standalone.d.ts(11165,28): error TS1005: ';' expected.
44+
typescript_standalone.d.ts(11165,40): error TS1005: ';' expected.
45+
typescript_standalone.d.ts(11199,28): error TS1005: ';' expected.
46+
typescript_standalone.d.ts(11199,40): error TS1005: ';' expected.
47+
typescript_standalone.d.ts(11210,28): error TS1005: ';' expected.
48+
typescript_standalone.d.ts(11210,40): error TS1005: ';' expected.
49+
typescript_standalone.d.ts(11234,28): error TS1005: ';' expected.
50+
typescript_standalone.d.ts(11234,40): error TS1005: ';' expected.
51+
typescript_standalone.d.ts(11242,28): error TS1005: ';' expected.
52+
typescript_standalone.d.ts(11242,40): error TS1005: ';' expected.
53+
typescript_standalone.d.ts(11246,28): error TS1005: ';' expected.
54+
typescript_standalone.d.ts(11246,40): error TS1005: ';' expected.
55+
typescript_standalone.d.ts(11276,28): error TS1005: ';' expected.
56+
typescript_standalone.d.ts(11276,40): error TS1005: ';' expected.
57+
typescript_standalone.d.ts(11319,28): error TS1005: ';' expected.
58+
typescript_standalone.d.ts(11319,41): error TS1005: ';' expected.
6159
typescript_standalone.d.ts(11506,28): error TS1005: ';' expected.
6260
typescript_standalone.d.ts(11506,37): error TS1005: ';' expected.
63-
typescript_standalone.d.ts(11510,28): error TS1005: ';' expected.
64-
typescript_standalone.d.ts(11510,37): error TS1005: ';' expected.
61+
typescript_standalone.d.ts(11508,28): error TS1005: ';' expected.
62+
typescript_standalone.d.ts(11508,37): error TS1005: ';' expected.
6563
typescript_standalone.d.ts(11512,28): error TS1005: ';' expected.
6664
typescript_standalone.d.ts(11512,37): error TS1005: ';' expected.
6765
typescript_standalone.d.ts(11514,28): error TS1005: ';' expected.
@@ -70,8 +68,8 @@ typescript_standalone.d.ts(11516,28): error TS1005: ';' expected.
7068
typescript_standalone.d.ts(11516,37): error TS1005: ';' expected.
7169
typescript_standalone.d.ts(11518,28): error TS1005: ';' expected.
7270
typescript_standalone.d.ts(11518,37): error TS1005: ';' expected.
73-
typescript_standalone.d.ts(11527,28): error TS1005: ';' expected.
74-
typescript_standalone.d.ts(11527,37): error TS1005: ';' expected.
71+
typescript_standalone.d.ts(11520,28): error TS1005: ';' expected.
72+
typescript_standalone.d.ts(11520,37): error TS1005: ';' expected.
7573
typescript_standalone.d.ts(11529,28): error TS1005: ';' expected.
7674
typescript_standalone.d.ts(11529,37): error TS1005: ';' expected.
7775
typescript_standalone.d.ts(11531,28): error TS1005: ';' expected.
@@ -100,8 +98,8 @@ typescript_standalone.d.ts(11553,28): error TS1005: ';' expected.
10098
typescript_standalone.d.ts(11553,37): error TS1005: ';' expected.
10199
typescript_standalone.d.ts(11555,28): error TS1005: ';' expected.
102100
typescript_standalone.d.ts(11555,37): error TS1005: ';' expected.
103-
typescript_standalone.d.ts(11565,28): error TS1005: ';' expected.
104-
typescript_standalone.d.ts(11565,37): error TS1005: ';' expected.
101+
typescript_standalone.d.ts(11557,28): error TS1005: ';' expected.
102+
typescript_standalone.d.ts(11557,37): error TS1005: ';' expected.
105103
typescript_standalone.d.ts(11567,28): error TS1005: ';' expected.
106104
typescript_standalone.d.ts(11567,37): error TS1005: ';' expected.
107105
typescript_standalone.d.ts(11569,28): error TS1005: ';' expected.
@@ -115,19 +113,21 @@ typescript_standalone.d.ts(11575,37): error TS1005: ';' expected.
115113
typescript_standalone.d.ts(11577,28): error TS1005: ';' expected.
116114
typescript_standalone.d.ts(11577,37): error TS1005: ';' expected.
117115
typescript_standalone.d.ts(11579,28): error TS1005: ';' expected.
118-
typescript_standalone.d.ts(11579,72): error TS1005: ';' expected.
116+
typescript_standalone.d.ts(11579,37): error TS1005: ';' expected.
119117
typescript_standalone.d.ts(11581,28): error TS1005: ';' expected.
120-
typescript_standalone.d.ts(11581,52): error TS1005: ';' expected.
121-
typescript_standalone.d.ts(11653,28): error TS1005: ';' expected.
122-
typescript_standalone.d.ts(11653,72): error TS1005: ';' expected.
118+
typescript_standalone.d.ts(11581,72): error TS1005: ';' expected.
119+
typescript_standalone.d.ts(11583,28): error TS1005: ';' expected.
120+
typescript_standalone.d.ts(11583,52): error TS1005: ';' expected.
123121
typescript_standalone.d.ts(11655,28): error TS1005: ';' expected.
124-
typescript_standalone.d.ts(11655,38): error TS1005: ';' expected.
122+
typescript_standalone.d.ts(11655,72): error TS1005: ';' expected.
125123
typescript_standalone.d.ts(11657,28): error TS1005: ';' expected.
126-
typescript_standalone.d.ts(11657,71): error TS1005: ';' expected.
124+
typescript_standalone.d.ts(11657,38): error TS1005: ';' expected.
127125
typescript_standalone.d.ts(11659,28): error TS1005: ';' expected.
128-
typescript_standalone.d.ts(11659,40): error TS1005: ';' expected.
129-
typescript_standalone.d.ts(11735,28): error TS1005: ';' expected.
130-
typescript_standalone.d.ts(11735,48): error TS1005: ';' expected.
126+
typescript_standalone.d.ts(11659,71): error TS1005: ';' expected.
127+
typescript_standalone.d.ts(11661,28): error TS1005: ';' expected.
128+
typescript_standalone.d.ts(11661,40): error TS1005: ';' expected.
129+
typescript_standalone.d.ts(11737,28): error TS1005: ';' expected.
130+
typescript_standalone.d.ts(11737,48): error TS1005: ';' expected.
131131

132132

133133
==== tests/cases/compiler/APISample_Watch.ts (0 errors) ====

0 commit comments

Comments
 (0)