microsoft / microsoft/TypeScript
--esModuleInterop: Strange incompatibility between correct and incorrect import of same type
Open
Nobody has claimed this yet.
Domain: Error Messages
Experience Enhancement
In Discussion
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: master
Code
b.d.ts
declare class C {
f: this;
}
declare namespace C {}
export = C;
a.ts
import * as C1 from "./b";
import C2 = require("./b");
function f(t: (c: C1) => void): void {
t(new C2());
}
Expected behavior:
Error at import * as C1.
Actual behavior:
No error at the import declaration. Error at new C2():
src/a.ts(5,7): error TS2345: Argument of type 'C' is not assignable to parameter of type 'C'.
Types of property 'f' are incompatible.
Type 'C' is not assignable to type 'this'.
(possibly related: #20704)
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 report using b.d.ts and a.ts exactly as shown, then run the TypeScript checker to observe the diagnostic at new C2(). Start by tracing how import * as C1, import-equals require, export =, and the this-typed property are compared. Done means the incompatibility is handled consistently, with the expected diagnostic location or behavior covered by a regression test.
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