microsoft / microsoft/TypeScript

Rest tuple parameter with intersection/union places error on wrong argument

Aperta
#28,505 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: Error Messages
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

TypeScript Version: 3.2.0-dev.20181113

Search Terms:
rest tuple, intersection, union, error, argument, misplaced

Code

declare function boop<T extends any[]>(...args: T & [number, string]): void;
boop(123, 456); // error
//   ~~~ <-- error on first argument
// Argument of type '[123, 456]' is not assignable to parameter 
//   of type '[number, number] & [number, string]'.
// Type '[123, 456]' is not assignable to type '[number, string]'.
// Type '456' is not assignable to type 'string'.

Expected behavior:
I expect an error on the second argument (456), since that's the argument that causes the failure, as made evident by the error message. (Or possibly I expect an error on both arguments, if it's interpreted as a failure to match the rest parameter.)

Actual behavior:
The actual error is on the first argument (123). This is a minor problem, and it only seems to show up in the intersection-with-type-parameter situation above (concrete types like ...args: [number, string] & [number, string] work fine), but I figured I'd report it in case it has an easy fix.

(Note to self or interested non-selves: ran into this in a Stack Overflow answer)

Playground Link:
🔗

Related Issues:
Haven't found anything. Anyone find anything?

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Iniziare con la riproduzione fornita in TypeScript Playground e confrontare l’intervallo della diagnostica segnalato con l’argomento che dovrebbe fallire. Tracciare la gestione da parte del compilatore dei parametri tupla rest combinati con un’intersezione di parametri di tipo, quindi verificare che la diagnostica punti al secondo argomento senza introdurre una regressione nel caso di intersezione concreta.

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
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.