microsoft / microsoft/TypeScript
Empty rest parameter type inferred from candidate function with no rest parameters when "best match" contains a contextually typed argument
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Bug Report
🔎 Search Terms
Rest parameter inference contextual
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about type inference
⏯ Playground Link
Playground link with relevant code
💻 Code
const doSomething = <Args extends unknown[]>(
fn1: (aNumber: number, ...rest: Args) => void,
fn2: (aNumber: number, ...rest: Args) => void,
) => {}
// OK, no contextual types
doSomething(
(explicit: number, rest: string) => {}, // Args = [string]
() => {},
)
// OK (both contain contextually typed arg)
doSomething(
(contextual, rest: string) => {}, // Args = [string]
(contextual) => {},
)
// Contextually type only fn1 - Not ok
doSomething(
(contextual, rest: string) => {}, // ERROR
() => {}, // Args = []
)
doSomething(
(contextual, rest: string) => {}, // ERROR
(explicit: number) => {}, // Args = []
)
🙁 Actual behavior
When fn1 (and only fn1) contains a contextually typed argument, it is ignored in favour of fn2
🙂 Expected behavior
In all of the examples, fn2 specifies no rest parameters at all.
I would expect functions that do not specify any rest parameters to always be the least preferable candidate (lowest weight?) for rest parameter inference, since "no rest parameters" can always be assigned to any rest parameter type.
Guida per i contributori
Apri 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.
Direzione di ricerca
Inizia con la riproduzione collegata in TypeScript Playground e riduci le tre chiamate a doSomething per isolare in che modo il contextual typing influisce sull'inferenza dei parametri rest. Segui il percorso di type-checking che seleziona i candidati per l'inferenza, quindi aggiungi un test di regressione per i casi mostrati; il lavoro è concluso quando il tipo rest [string] di fn1 non viene sostituito da [] di fn2.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100