Skip to content

Imported variables that used in string switch are not imported correctly in output #5645

Closed

Description

I experienced the following problem:

Problem

Variables that are imported with import statement and used in switch statement with string parameter
are not imported correctly in emitted JavaScript (no import statement emitted for those variables).

Using other types than string in switch does not cause the problem oddly.

Version

Version 1.8.0-dev.20151112

Code

mod.ts

export const foo = 1;
export const bar = "2";

test.ts

import {foo, bar} from "./mod";

switch ("foo") {
  case "foo": {
    foo;
  }
  case "bar": {
    bar;
  }
}

Command

tsc test.ts --target es6

Output

tsc does not generate import statement for foo and bar.

test.js

switch ("foo") {
    case "foo":
        foo;
    case "bar":
        bar;
}

Activity

  1. seanchas116 commented on Nov 13, 2015

    @seanchas116
    ContributorAuthor

    This problem seems to be introduced since 1.8.0-dev.20151110.

  2. seanchas116 commented on Nov 13, 2015

    @seanchas116
    ContributorAuthor

    I noticed whole type checking doesn't work inside switch (any wrong code inside switch compiles without errors)...

  3. seanchas116 commented on Nov 13, 2015

    @seanchas116
    ContributorAuthor

    Oh this is fixed in #5639

  4. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions