Skip to content

--noImplicitAny error not reported for variable declaration #30899

Closed
@mjbvz

Description

@mjbvz

TypeScript Version: 3.5.0-dev.20190412

Search Terms:

Code
Compile the following ts with --noImplicitAny

let x;
if (Date.now()) {
    x = 1;
} else {
    x = { obj: true };
}

foo(x);

function foo(y) { }

Expected behavior:
The declaration let x should produce an implicit any error

Actual behavior:
No error reported. After the assignment, the type of x is number | { obj: boolean }

Playground Link:
https://www.typescriptlang.org/play/#src=let%20x%3B%0D%0Aif%20(Date.now())%20%7B%0D%0A%20%20%20%20x%20%3D%201%3B%0D%0A%7D%20else%20%7B%0D%0A%20%20%20%20x%20%3D%20%7B%20obj%3A%20true%20%7D%3B%0D%0A%7D%0D%0A%0D%0Afoo(x)%3B%0D%0A%0D%0Afunction%20foo(y)%20%7B%20%7D

Related Issues:
From microsoft/vscode#72193

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions