microsoft / microsoft/TypeScript
Named import for 'any'-typed module doesn't work
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Bug Report
🔎 Search Terms
any module export assignment named import
🕗 Version & Regression Information
TypeScript v4.1.2
💻 Code
mock.d.ts
declare const _: any;
export = _;
example.ts
import { a } from "./mock";
import * as b from "./mock";
const { c } = b;
const { d } = await import("./mock");
console.log(a, c, d);
tsconfig.json
{
"compilerOptions": {
"module": "ESNext",
"strict": true,
"target": "ESNext",
},
"include": [
"./**/*.ts"
]
}
🙁 Actual behavior
The first import returns the diagnostic:
error TS2305: Module '"./mock"' has no exported member 'a'.
While c and d do not error.
🙂 Expected behavior
With an export being effectively any, I would expect default, namespace, dynamic and named imports to all behave as if the module was any. I cannot find any other way to declare a module in a fashion where the compiler treats any import from that module as any and does not issue diagnostics.
As implied in the above, there are certain situations where there is a need to "mock" a module where its shape cannot be statically determined at compile time.
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 mock.d.ts, example.ts, and tsconfig.json, then trace the TypeScript compiler's handling of named imports from an export-assignment module typed as any. Done means the named import no longer reports TS2305 while retaining the behavior shown for namespace and dynamic imports.
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
- Mostly clear
- Newbie friendliness
- 35/100