microsoft / microsoft/TypeScript
Missing error when awaiting dynamic import of module with 'then' export
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.0.0-dev.20180605
Search Terms:
Code
// a.ts
export function then() { return true; }
// b.ts
async function test() {
await import('./a');
}
// c.ts
// this is basically the same as b.ts
import * as ns from './a';
function myImport() {
return Promise.resolve(ns);
}
async function test() {
await myImport();
}
Expected behavior:
in b.ts: [ts] Type of 'await' operand must either be a valid promise or must not contain a callable 'then' member.
This would catch a lot of bugs with dynamic imports of modules that contain a then function. The resulting Promise will never resolve: https://github.com/tc39/proposal-dynamic-import/issues/47
Actual behavior:
No error in b.ts. The resulting type of the await is {}.
Playground Link:
Related Issues:
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
Start by reproducing the a.ts, b.ts, and c.ts examples with the reported TypeScript version, then compare dynamic import handling with the Promise.resolve namespace case. Trace the await operand checking and dynamic-import type inference. Done means b.ts reports the callable then diagnostic and a regression test covers the module export case.
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