microsoft / microsoft/TypeScript
"export = { }" vs "let a = { }; export = a", causes discrepancy in import behavior
Open
Nobody has claimed this yet.
Needs Investigation
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.9.5
Search Terms: I searched import related bug labels
Code
//module a
export = {
name: 'zzxoto'
};
//module b
const EX = { name: 'zzxoto' };
export = EX;
//////////////////////////////////////////////////////////////////
//when importing a
//this gives error:
//This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.ts(2497)
import { name } from './a';
//this works
import A from './a';
A.name;
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//when importing b
//this works
import { name } from './b';
//this works too
import B from './b';
B.name
//////////////////////////////////////////////////////////////////
//tsconfig.json
{
"compilerOptions": {
"target": "ES2019",
"module": "commonjs",
"strict": false,
"strictNullChecks": true,
"allowJs": false,
"esModuleInterop": true
},
"include": ["**/*.ts"]
}
Expected behavior:
There should be no descrepancy while import module a vs module b.
Actual behavior:
Described above.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the discrepancy using modules a and b from the report with TypeScript 3.9.5 and the provided tsconfig.json. Compare named and default imports under esModuleInterop, then verify that equivalent export forms produce consistent import 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
- 45/100