microsoft / microsoft/TypeScript
Reordering variable declarations of Promise<any> and Promise<unknown> changes behavior
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
🔎 Search Terms
Promise<any> Promise<unknown> instantiation order
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ
⏯ Playground Link
Playground link with relevant code
💻 Code
// Reorder these two
declare let u: Promise<unknown>
declare let a: Promise<any>
// Assigned an expression that is Promise<any> | Promise<unknown>
// but that will undergo subtype reduction
// The type of union depends on whether a or u was declared first
let union = Math.random() > 0.5
? Promise.reject<any>()
: Promise.reject<unknown>();
union.then(v => v.toString());
🙁 Actual behavior
Reordering the unrelated variables u and a will cause the type of union to change between Promise<unknown> and Promise<any> (both in declarations and in the type of v, although tooltips still show union as Promise<any>)
🙂 Expected behavior
The type of union should not be impacted
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 behavior using the linked TypeScript Playground and the two declaration-order variants in the report. Investigate subtype reduction for the Promise and Promise union, then verify that reordering the unrelated declarations leaves the inferred type of union and the callback value unchanged.
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