Skip to content

Disable evolving types with implicit any #12362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3238,9 +3238,11 @@ namespace ts {
return addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ declaration.questionToken && includeOptionality);
}

if (declaration.kind === SyntaxKind.VariableDeclaration && !isBindingPattern(declaration.name) &&
if ((compilerOptions.noImplicitAny || declaration.flags & NodeFlags.JavaScriptFile) &&
declaration.kind === SyntaxKind.VariableDeclaration && !isBindingPattern(declaration.name) &&
!(getCombinedModifierFlags(declaration) & ModifierFlags.Export) && !isInAmbientContext(declaration)) {
// Use control flow tracked 'any' type for non-ambient, non-exported var or let variables with no
// If --noImplicitAny is on or the declaration is in a Javascript file,
// use control flow tracked 'any' type for non-ambient, non-exported var or let variables with no
// initializer or a 'null' or 'undefined' initializer.
if (!(getCombinedNodeFlags(declaration) & NodeFlags.Const) && (!declaration.initializer || isNullOrUndefined(declaration.initializer))) {
return autoType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ var Foo;
>Foo : any

type
>type : undefined
>type : any

Foo = string;
>Foo = string : undefined
>Foo = string : any
>Foo : any
>string : undefined
>string : any

4 changes: 2 additions & 2 deletions tests/baselines/reference/assignEveryTypeToAny.types
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ var e = undefined;
>undefined : undefined

x = e;
>x = e : undefined
>x = e : any
>x : any
>e : undefined
>e : any

var e2: typeof undefined;
>e2 : any
Expand Down
24 changes: 12 additions & 12 deletions tests/baselines/reference/capturedLetConstInLoop3.types
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function foo3(x) {
use(v);
>use(v) : any
>use : (a: any) => any
>v : undefined
>v : any
}

function foo4(x) {
Expand Down Expand Up @@ -283,8 +283,8 @@ function foo6(x) {
>y : any

var v = x;
>v : undefined
>x : undefined
>v : any
>x : any

(function() { return x + y + v });
>(function() { return x + y + v }) : () => any
Expand All @@ -293,7 +293,7 @@ function foo6(x) {
>x + y : any
>x : any
>y : any
>v : undefined
>v : any

(() => x + y + v);
>(() => x + y + v) : () => any
Expand All @@ -302,13 +302,13 @@ function foo6(x) {
>x + y : any
>x : any
>y : any
>v : undefined
>v : any
}

use(v)
>use(v) : any
>use : (a: any) => any
>v : undefined
>v : any
}

function foo7(x) {
Expand All @@ -321,8 +321,8 @@ function foo7(x) {
>y : any

var v = x;
>v : undefined
>x : undefined
>v : any
>x : any

(function() { return x + y + v });
>(function() { return x + y + v }) : () => any
Expand All @@ -331,7 +331,7 @@ function foo7(x) {
>x + y : any
>x : any
>y : any
>v : undefined
>v : any

(() => x + y + v);
>(() => x + y + v) : () => any
Expand All @@ -340,7 +340,7 @@ function foo7(x) {
>x + y : any
>x : any
>y : any
>v : undefined
>v : any

} while (1 === 1);
>1 === 1 : boolean
Expand All @@ -350,7 +350,7 @@ function foo7(x) {
use(v);
>use(v) : any
>use : (a: any) => any
>v : undefined
>v : any
}


Expand Down Expand Up @@ -574,7 +574,7 @@ function foo3_c(x) {
use(v);
>use(v) : any
>use : (a: any) => any
>v : undefined
>v : any
}

function foo4_c(x) {
Expand Down
24 changes: 12 additions & 12 deletions tests/baselines/reference/capturedLetConstInLoop3_ES6.types
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function foo3(x) {
use(v);
>use(v) : any
>use : (a: any) => any
>v : undefined
>v : any
}

function foo4(x) {
Expand Down Expand Up @@ -284,8 +284,8 @@ function foo6(x) {
>y : any

var v = x;
>v : undefined
>x : undefined
>v : any
>x : any

(function() { return x + y + v });
>(function() { return x + y + v }) : () => any
Expand All @@ -294,7 +294,7 @@ function foo6(x) {
>x + y : any
>x : any
>y : any
>v : undefined
>v : any

(() => x + y + v);
>(() => x + y + v) : () => any
Expand All @@ -303,13 +303,13 @@ function foo6(x) {
>x + y : any
>x : any
>y : any
>v : undefined
>v : any
}

use(v)
>use(v) : any
>use : (a: any) => any
>v : undefined
>v : any
}

function foo7(x) {
Expand All @@ -322,8 +322,8 @@ function foo7(x) {
>y : any

var v = x;
>v : undefined
>x : undefined
>v : any
>x : any

(function() { return x + y + v });
>(function() { return x + y + v }) : () => any
Expand All @@ -332,7 +332,7 @@ function foo7(x) {
>x + y : any
>x : any
>y : any
>v : undefined
>v : any

(() => x + y + v);
>(() => x + y + v) : () => any
Expand All @@ -341,7 +341,7 @@ function foo7(x) {
>x + y : any
>x : any
>y : any
>v : undefined
>v : any

} while (1 === 1);
>1 === 1 : boolean
Expand All @@ -351,7 +351,7 @@ function foo7(x) {
use(v);
>use(v) : any
>use : (a: any) => any
>v : undefined
>v : any
}


Expand Down Expand Up @@ -575,7 +575,7 @@ function foo3_c(x) {
use(v);
>use(v) : any
>use : (a: any) => any
>v : undefined
>v : any
}

function foo4_c(x) {
Expand Down
32 changes: 16 additions & 16 deletions tests/baselines/reference/capturedLetConstInLoop4.types
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export function exportedFoo() {
>v0 : any
>v00 : string
>v1 : number
>v2 : undefined
>v3 : undefined
>v2 : any
>v3 : any
>v4 : number
>v5 : number
>v6 : undefined
>v7 : undefined
>v6 : any
>v7 : any
>v8 : number
}

Expand Down Expand Up @@ -103,15 +103,15 @@ while (1 === 1) {
>x : any

var v2 = x;
>v2 : undefined
>x : undefined
>v2 : any
>x : any

(function() { return x + v2});
>(function() { return x + v2}) : () => any
>function() { return x + v2} : () => any
>x + v2 : any
>x : any
>v2 : undefined
>v2 : any

(() => x);
>(() => x) : () => any
Expand All @@ -124,15 +124,15 @@ do {
>x : any

var v3 = x;
>v3 : undefined
>x : undefined
>v3 : any
>x : any

(function() { return x + v3});
>(function() { return x + v3}) : () => any
>function() { return x + v3} : () => any
>x + v3 : any
>x : any
>v3 : undefined
>v3 : any

(() => x);
>(() => x) : () => any
Expand Down Expand Up @@ -216,8 +216,8 @@ while (1 === 1) {
>y : any

var v6 = x;
>v6 : undefined
>x : undefined
>v6 : any
>x : any

(function() { return x + y + v6});
>(function() { return x + y + v6}) : () => any
Expand All @@ -226,7 +226,7 @@ while (1 === 1) {
>x + y : any
>x : any
>y : any
>v6 : undefined
>v6 : any

(() => x + y);
>(() => x + y) : () => any
Expand All @@ -242,8 +242,8 @@ do {
>y : any

var v7 = x;
>v7 : undefined
>x : undefined
>v7 : any
>x : any

(function() { return x + y + v7});
>(function() { return x + y + v7}) : () => any
Expand All @@ -252,7 +252,7 @@ do {
>x + y : any
>x : any
>y : any
>v7 : undefined
>v7 : any

(() => x + y);
>(() => x + y) : () => any
Expand Down
Loading