microsoft / microsoft/TypeScript

`esModuleInterop` breaks circular imports

Open
#33,012 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: ES Modules
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.5.2

Search Terms:

Code

./tsconfig.json:

{
    "compilerOptions": {
        "esModuleInterop": true
    },
    "files": ["./src/main.ts"]
}

./src/main.ts

import { other } from './other';

console.log(other.foo1);

./src/other.ts

export const foo1 = 1;
export const foo2 = 2;

// Import *this* module as a namespace
// Unexpected error:
// Circular definition of import alias 'other'
import * as other from './other';

// Re-export the namespace as a named export
export { other };

(For context on why you might do this: it allows you to give namespace imports a common name.)

Expected behavior:

No error

Actual behavior:

Error (see code comment)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the diagnostic with ./tsconfig.json, src/main.ts, and src/other.ts using TypeScript 3.5.2 or the relevant current version. Start by tracing the circular import alias check for the namespace import in src/other.ts; done means the example compiles without the reported error while preserving the expected import and re-export behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.