Skip to content

Variable declaration using "let" keyword fails in "for" statements  #20435

@koutoftimer

Description

@koutoftimer

TypeScript Version 2.6.2

Code

example1.ts

let i = 1;
for (i = 0; i < 10; ++i) let i = 2;

example1.js

var i = 1;
for (i_1 = 0; i_1 < 10; ++i_1)
    var i_1 = 2;

example2.ts

let i = 1;
for (i = 0; i < 10; ++i) { let i = 2; }

example2.js

var i = 1;
for (i = 0; i < 10; ++i) {
    var i_1 = 2;
}

Expected behavior:
example1.ts and example2.ts are identical and shows us an ability to declare variables with the same name in the inner scope. In both cases counter variable for for statement should be used from the outer scope.

Actual behavior:
example1.ts fail compilation. Counter variable became global with the name of inner scope variable.

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