microsoft / microsoft/TypeScript
functions with destructuring parameters are not inferred as type predicate correctly
Open
Nobody has claimed this yet.
Awaiting More Feedback
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
infer type predicate, destructuring
🕗 Version & Regression Information
- This changed between versions 5.5
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
💻 Code
type X = { type: 'A'; a: string } | { type: 'B'; b: string };
let xs: X[] = [];
// should not error
const filtered1: { type: 'A'; a: string }[] = xs
.filter(({ type }) => type === 'A');
const filtered2: { type: 'A'; a: string }[] = xs
.filter(x => x.type === 'A');
🙁 Actual behavior
error on filtered1
🙂 Expected behavior
not error on filtered1
Additional information about the issue
No response
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 with the linked TypeScript Playground reproduction and compare the destructured-parameter callback with the direct-parameter callback. Trace type-predicate inference for filter callbacks and verify completion when filtered1 accepts the narrowed array type without an error.
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
- 45/100