microsoft / microsoft/TypeScript
A tuple containing a spread not at the trailing edge has its minimum length calculated incorrectly
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
- tuple
- spread
🕗 Version & Regression Information
It happens in v4.9.5, no idea about other versions.
⏯ Playground Link
💻 Code
type FN1 <T> = (...args: string[]) => T;
type FN2 <T> = ( ...args: [consumed: string, ...groups: string[], input: string, index: string] ) => T;
const fn1: FN1<number> = ( a, b ) => 0;
const fn2: FN2<number> = ( a, b ) => 0;
🙁 Actual behavior
TS complains about my fn2, with the following error:
Type '(a: string, b: string) => number' is not assignable to type 'FN2<number>'.
Types of parameters 'b' and 'groups' are incompatible.
Type '[...groups: string[], input: string, index: string]' is not assignable to type '[b: string]'.
Source has 2 element(s) but target allows only 1.(2322)
If I'm interpreting it correctly it is saying like "hey you defined two arguments, but maybe this tuple only has one item in it.
🙂 Expected behavior
If I'm interpreting the error correctly then the error is wrong because there's no scenario where that tuple has just one item in it, minimum it will always have 3.
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
Riproduci il report nel TypeScript Playground collegato usando i tipi tupla e funzione dell’issue. Traccia il calcolo della lunghezza minima delle tuple effettuato dal compilatore per gli spread in posizioni non finali. Il lavoro è completato quando l’esempio non segnala più che la tupla sorgente può contenere un solo elemento, mentre il comportamento diagnostico esistente rimane corretto per le tuple effettivamente troppo corte.
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
- Abbastanza chiara
- Idoneità per principianti
- 48/100