Skip to content

Commit b514d7c

Browse files
authored
Merge pull request #12362 from Microsoft/disable-evolving-types-with-implicit-any
Disable evolving types with implicit any
2 parents f626ff7 + 7750fe1 commit b514d7c

Some content is hidden

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

48 files changed

+577
-912
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3239,9 +3239,11 @@ namespace ts {
32393239
return addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ declaration.questionToken && includeOptionality);
32403240
}
32413241

3242-
if (declaration.kind === SyntaxKind.VariableDeclaration && !isBindingPattern(declaration.name) &&
3242+
if ((compilerOptions.noImplicitAny || declaration.flags & NodeFlags.JavaScriptFile) &&
3243+
declaration.kind === SyntaxKind.VariableDeclaration && !isBindingPattern(declaration.name) &&
32433244
!(getCombinedModifierFlags(declaration) & ModifierFlags.Export) && !isInAmbientContext(declaration)) {
3244-
// Use control flow tracked 'any' type for non-ambient, non-exported var or let variables with no
3245+
// If --noImplicitAny is on or the declaration is in a Javascript file,
3246+
// use control flow tracked 'any' type for non-ambient, non-exported var or let variables with no
32453247
// initializer or a 'null' or 'undefined' initializer.
32463248
if (!(getCombinedNodeFlags(declaration) & NodeFlags.Const) && (!declaration.initializer || isNullOrUndefined(declaration.initializer))) {
32473249
return autoType;

tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ var Foo;
1010
>Foo : any
1111

1212
type
13-
>type : undefined
13+
>type : any
1414

1515
Foo = string;
16-
>Foo = string : undefined
16+
>Foo = string : any
1717
>Foo : any
18-
>string : undefined
18+
>string : any
1919

tests/baselines/reference/assignEveryTypeToAny.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ var e = undefined;
5959
>undefined : undefined
6060

6161
x = e;
62-
>x = e : undefined
62+
>x = e : any
6363
>x : any
64-
>e : undefined
64+
>e : any
6565

6666
var e2: typeof undefined;
6767
>e2 : any

tests/baselines/reference/capturedLetConstInLoop3.types

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ function foo3(x) {
179179
use(v);
180180
>use(v) : any
181181
>use : (a: any) => any
182-
>v : undefined
182+
>v : any
183183
}
184184

185185
function foo4(x) {
@@ -283,8 +283,8 @@ function foo6(x) {
283283
>y : any
284284

285285
var v = x;
286-
>v : undefined
287-
>x : undefined
286+
>v : any
287+
>x : any
288288

289289
(function() { return x + y + v });
290290
>(function() { return x + y + v }) : () => any
@@ -293,7 +293,7 @@ function foo6(x) {
293293
>x + y : any
294294
>x : any
295295
>y : any
296-
>v : undefined
296+
>v : any
297297

298298
(() => x + y + v);
299299
>(() => x + y + v) : () => any
@@ -302,13 +302,13 @@ function foo6(x) {
302302
>x + y : any
303303
>x : any
304304
>y : any
305-
>v : undefined
305+
>v : any
306306
}
307307

308308
use(v)
309309
>use(v) : any
310310
>use : (a: any) => any
311-
>v : undefined
311+
>v : any
312312
}
313313

314314
function foo7(x) {
@@ -321,8 +321,8 @@ function foo7(x) {
321321
>y : any
322322

323323
var v = x;
324-
>v : undefined
325-
>x : undefined
324+
>v : any
325+
>x : any
326326

327327
(function() { return x + y + v });
328328
>(function() { return x + y + v }) : () => any
@@ -331,7 +331,7 @@ function foo7(x) {
331331
>x + y : any
332332
>x : any
333333
>y : any
334-
>v : undefined
334+
>v : any
335335

336336
(() => x + y + v);
337337
>(() => x + y + v) : () => any
@@ -340,7 +340,7 @@ function foo7(x) {
340340
>x + y : any
341341
>x : any
342342
>y : any
343-
>v : undefined
343+
>v : any
344344

345345
} while (1 === 1);
346346
>1 === 1 : boolean
@@ -350,7 +350,7 @@ function foo7(x) {
350350
use(v);
351351
>use(v) : any
352352
>use : (a: any) => any
353-
>v : undefined
353+
>v : any
354354
}
355355

356356

@@ -574,7 +574,7 @@ function foo3_c(x) {
574574
use(v);
575575
>use(v) : any
576576
>use : (a: any) => any
577-
>v : undefined
577+
>v : any
578578
}
579579

580580
function foo4_c(x) {

tests/baselines/reference/capturedLetConstInLoop3_ES6.types

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function foo3(x) {
180180
use(v);
181181
>use(v) : any
182182
>use : (a: any) => any
183-
>v : undefined
183+
>v : any
184184
}
185185

186186
function foo4(x) {
@@ -284,8 +284,8 @@ function foo6(x) {
284284
>y : any
285285

286286
var v = x;
287-
>v : undefined
288-
>x : undefined
287+
>v : any
288+
>x : any
289289

290290
(function() { return x + y + v });
291291
>(function() { return x + y + v }) : () => any
@@ -294,7 +294,7 @@ function foo6(x) {
294294
>x + y : any
295295
>x : any
296296
>y : any
297-
>v : undefined
297+
>v : any
298298

299299
(() => x + y + v);
300300
>(() => x + y + v) : () => any
@@ -303,13 +303,13 @@ function foo6(x) {
303303
>x + y : any
304304
>x : any
305305
>y : any
306-
>v : undefined
306+
>v : any
307307
}
308308

309309
use(v)
310310
>use(v) : any
311311
>use : (a: any) => any
312-
>v : undefined
312+
>v : any
313313
}
314314

315315
function foo7(x) {
@@ -322,8 +322,8 @@ function foo7(x) {
322322
>y : any
323323

324324
var v = x;
325-
>v : undefined
326-
>x : undefined
325+
>v : any
326+
>x : any
327327

328328
(function() { return x + y + v });
329329
>(function() { return x + y + v }) : () => any
@@ -332,7 +332,7 @@ function foo7(x) {
332332
>x + y : any
333333
>x : any
334334
>y : any
335-
>v : undefined
335+
>v : any
336336

337337
(() => x + y + v);
338338
>(() => x + y + v) : () => any
@@ -341,7 +341,7 @@ function foo7(x) {
341341
>x + y : any
342342
>x : any
343343
>y : any
344-
>v : undefined
344+
>v : any
345345

346346
} while (1 === 1);
347347
>1 === 1 : boolean
@@ -351,7 +351,7 @@ function foo7(x) {
351351
use(v);
352352
>use(v) : any
353353
>use : (a: any) => any
354-
>v : undefined
354+
>v : any
355355
}
356356

357357

@@ -575,7 +575,7 @@ function foo3_c(x) {
575575
use(v);
576576
>use(v) : any
577577
>use : (a: any) => any
578-
>v : undefined
578+
>v : any
579579
}
580580

581581
function foo4_c(x) {

tests/baselines/reference/capturedLetConstInLoop4.types

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export function exportedFoo() {
1717
>v0 : any
1818
>v00 : string
1919
>v1 : number
20-
>v2 : undefined
21-
>v3 : undefined
20+
>v2 : any
21+
>v3 : any
2222
>v4 : number
2323
>v5 : number
24-
>v6 : undefined
25-
>v7 : undefined
24+
>v6 : any
25+
>v7 : any
2626
>v8 : number
2727
}
2828

@@ -103,15 +103,15 @@ while (1 === 1) {
103103
>x : any
104104

105105
var v2 = x;
106-
>v2 : undefined
107-
>x : undefined
106+
>v2 : any
107+
>x : any
108108

109109
(function() { return x + v2});
110110
>(function() { return x + v2}) : () => any
111111
>function() { return x + v2} : () => any
112112
>x + v2 : any
113113
>x : any
114-
>v2 : undefined
114+
>v2 : any
115115

116116
(() => x);
117117
>(() => x) : () => any
@@ -124,15 +124,15 @@ do {
124124
>x : any
125125

126126
var v3 = x;
127-
>v3 : undefined
128-
>x : undefined
127+
>v3 : any
128+
>x : any
129129

130130
(function() { return x + v3});
131131
>(function() { return x + v3}) : () => any
132132
>function() { return x + v3} : () => any
133133
>x + v3 : any
134134
>x : any
135-
>v3 : undefined
135+
>v3 : any
136136

137137
(() => x);
138138
>(() => x) : () => any
@@ -216,8 +216,8 @@ while (1 === 1) {
216216
>y : any
217217

218218
var v6 = x;
219-
>v6 : undefined
220-
>x : undefined
219+
>v6 : any
220+
>x : any
221221

222222
(function() { return x + y + v6});
223223
>(function() { return x + y + v6}) : () => any
@@ -226,7 +226,7 @@ while (1 === 1) {
226226
>x + y : any
227227
>x : any
228228
>y : any
229-
>v6 : undefined
229+
>v6 : any
230230

231231
(() => x + y);
232232
>(() => x + y) : () => any
@@ -242,8 +242,8 @@ do {
242242
>y : any
243243

244244
var v7 = x;
245-
>v7 : undefined
246-
>x : undefined
245+
>v7 : any
246+
>x : any
247247

248248
(function() { return x + y + v7});
249249
>(function() { return x + y + v7}) : () => any
@@ -252,7 +252,7 @@ do {
252252
>x + y : any
253253
>x : any
254254
>y : any
255-
>v7 : undefined
255+
>v7 : any
256256

257257
(() => x + y);
258258
>(() => x + y) : () => any

0 commit comments

Comments
 (0)