Skip to content

Variable is considered undefined in for-of loop when target is es6 #8357

Description

@ivogabe

The variable in a for-of loop contains undefined when the target is set to es6. For es5, everything works as expected.

TypeScript Version:

nightly (1.9.0-dev.20160428)

Code

for (const x of ["a", "b"]) {
    x.substring;
}

tsconfig.json:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "strictNullChecks": true
    }
}

Expected behavior:
Type of x is string in the loop body, no compile error.

Actual behavior:
Type of x is string | undefined, which gives an error.

@ahejlsberg

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions