microsoft / microsoft/TypeScript
type gets widened on declaration emit when inferred in destructuring context
Open
Nobody has claimed this yet.
Bug
Domain: Declaration Emit
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
declaration, widened, d.ts, destructuring
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries
⏯ Playground Link
💻 Code
function foo(): {y: 1} {
return { y: 1 }
}
export const { y = 0 } = foo();
🙁 Actual behavior
y is number in d.ts files, although the language service says y is 1|0
🙂 Expected behavior
y is 1|0 in d.ts files.
Additional information about the issue
Without the = 0 assignment y properly becomes type 1 in d.ts
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
Use the linked TypeScript Playground and the provided destructuring example to reproduce the declaration emit. Compare the generated d.ts type for y with the language service result, then verify that the emitted type remains 1|0 when the default assignment is present while the no-default case remains 1.
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