7.1: destructured parameter with a `= {}` default loses its contextual type (TS7031)
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 53/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
- Ambito
- compilers
Direzione di ricerca
Start by reading the compiler’s contextual parameter typing and destructuring code, then use the issue’s minimal reproduction to compare behavior across the affected 7.1 and working 7.0.2 versions. Add a regression test covering an optional contextually typed parameter with a destructuring pattern and an = {} default; done means both binding elements retain their contextual types without TS7031, while the two control cases still pass.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
🔎 Search Terms
TS7031, binding element implicitly has an any type, destructuring parameter default, contextual type, 7.1 regression
🕗 Version & Regression Information
- This changed between versions 7.0.2 and 7.1.0-beta
- Still present in 7.1.0-dev.20261026.1
- 6.0.3 and 7.0.2 report no errors
⏯ Playground Link
No response
💻 Code
// tsconfig: { "compilerOptions": { "strict": true, "noEmit": true, "skipLibCheck": true, "types": [] } }
type Fn = (input?: { channel?: string; minutes?: number }) => number;
export const f: Fn = ({ channel, minutes } = {}) => (channel ? 1 : 0) + (minutes ?? 0);
The error needs all three of: a destructuring pattern, an = {} initializer, and a contextually typed optional parameter. Each of these alone still checks cleanly on 7.1:
type F2 = (input: { channel?: string; minutes?: number }) => number;
export const f2: F2 = ({ channel, minutes }) => (channel ? 1 : 0) + (minutes ?? 0); // no initializer: OK
type G = (input?: { channel?: string }) => number;
export const g: G = (input = {}) => (input.channel ? 1 : 0); // identifier, not a pattern: OK
🙁 Actual behavior
a.ts(2,25): error TS7031: Binding element 'channel' implicitly has an 'any' type.
a.ts(2,34): error TS7031: Binding element 'minutes' implicitly has an 'any' type.
🙂 Expected behavior
No errors: channel and minutes take their types (string | undefined, number | undefined) from the contextual parameter type, as on 6.0.3 and 7.0.2.
Additional information about the issue
Found while trialling 7.1.0-beta on a large monorepo; it fires in test helpers and callbacks typed through an alias (({ a, b } = {}) => … assigned to a function type with an optional object parameter).
- Lingua principale
- Go
- Stelle
- 112k
- Fork
- 15.4k
- Merge medio
- 2g 21h
- PR unite (30g)
- 126
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/TypeScript
-
Won't Fix
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
microsoft/TypeScript#65107 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Native API: formatDiagnosticsWithColorAndContext drops related information without a file locationForse già presa @timurzvural l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
microsoft/TypeScript#65087 ·
I maintainer di solito rispondono entro 1 giorno
-
TS7 LSP: documentHighlight returns nothing when the file path contains '@'Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. ApertaBug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
microsoft/TypeScript#64758 ·
I maintainer di solito rispondono entro 1 giorno
-
Language server (tsc --lsp) exits with code 1 after `shutdown` and `exit`Forse già presa @rajnish-verma-22172 l’ha presa 12 giorni fa. ApertaBug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
microsoft/TypeScript#64742 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Class names `eval` and `arguments` are not reported as invalid strict mode bindingsForse già presa @dmety l’ha presa 26 giorni fa. ApertaBug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
microsoft/TypeScript#64661 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di microsoft/TypeScript
Issue simili
-
fix(scan): validate and normalize output format in validate-contractForse già presa @WKr1shna l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
argoproj/argo-workflows#17397 ·
I maintainer di solito rispondono entro 1 giorno
-
[mesheryctl] design delete fails when passing file or URL as positional argumentForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertacomponent/mesheryctl kind/bug language/go
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
meshery/meshery#22772 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno