Skip to content

dynamically imported module without import / export is treated as script by tsc #9593

@kt3k

Description

@kt3k

(Note: This probably doesn't affect any meaningful use cases, but I create issue for record.)

When we have the following scripts:

a.ts

const a = 1;
await import("./b.ts");

b.ts

const a = 2;

Then execute a.ts and it causes the following error.

$ deno run --allow-read a.ts
error: TS2451 [ERROR]: Cannot redeclare block-scoped variable 'a'.
const a = 2;
      ^
    at file:///Users/kt3k/0/di-test/b.ts:1:7

    'a' was also declared here.
    const a = 1;
          ^
        at file:///Users/kt3k/0/di-test/a.ts:1:7

This doesn't happen when:

  • b.ts has any import or export statement
  • import of b.ts is not dynamic import

$ deno --version
deno 1.7.5 (release, x86_64-apple-darwin)
v8 9.0.123
typescript 4.1.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working correctlyneeds discussionthis topic needs further discussion to determine what action to takeupstreamChanges in upstream are required to solve these issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions