Repository navigation
fix(64974): fix contextual typing for destructured parameter defaults - #64978
Oleksandr Tarasiuk (a-tarasyuk) wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
Static review identified no blocking issues in the focused fix and regression baselines; automated validation was not run.
No open issues 🎉
What changed in this PR
Fixes #64974 by preserving contextual types for destructured parameter defaults, preventing incorrect TS7031 errors.
Changes:
- Skip object-literal padding when the root parameter has a contextual type.
- Add regression cases for optional parameters, nested destructuring, arrays, index signatures, and generic callbacks.
- Update type, symbol, and diagnostic baselines.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/objectBindingPatternDefaultMissingElements.ts |
Adds contextual-typing regression cases. |
tsc/testdata/baselines/reference/compiler/objectBindingPatternDefaultMissingElements.types |
Records expected inferred types. |
tsc/testdata/baselines/reference/compiler/objectBindingPatternDefaultMissingElements.symbols |
Records symbols for the added cases. |
tsc/testdata/baselines/reference/compiler/objectBindingPatternDefaultMissingElements.errors.txt |
Records expected diagnostics without spurious implicit-any errors. |
tsc/internal/checker/checker.go |
Guards object-literal padding to preserve contextual typing. |
Review effort: Balanced
|
One more shape for the test file, from a codebase that hit this on 7.1: a pattern where some binding elements have their own defaults. Only the elements without a default are flagged; the ones with a default keep their type. // tsconfig: { "compilerOptions": { "strict": true, "noEmit": true, "target": "esnext", "module": "esnext", "types": [] } }
type Run = (argv: string[], options?: { cwd?: string; timeout?: number }) => void
export const run: Run = (argv, { cwd, timeout = 1 } = {}) => {
const n: number = timeout
console.log(argv, cwd, n)
}
|
|
Good catch — that mixed form is the same regression. On 7.1, padding invents I opened #65016 as an alternative that uses the same object-padding guard (and also guards array padding). I will add an explicit |
Fixes #64974