microsoft / microsoft/TypeScript

Tuple Spread Inconsistencies When Intersected

Aperta
#60,539 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

🔎 Search Terms

Tuple, Intersection, Spread

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about tuples and arrays
⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBAKgrmANtAvFA2gZ2AJwJYB2A5gDRQB0lBcAtgEYQ7oC6zA3AFCiSwLICSBYI0wQAxsDwB7AlDTwk0AGRQA3lDA4pYAFxRs+YlAC+nDl3DQFyAEoRsAQTFj7mOb0XoAjOw4B6PygggD0oanpGc24rPghBYRxRCWkCO0dnV3drOKERcUkZb18AoKhQg0IiKAAfMNoGHHMLHmyAZU0IAEMAE3d0SnJs4sDSsowK4jIB8IaWZijLDwFcxPyU9pwu3rR+ymz4vOSZYdLQgAoJqtqZxgBKFiA

💻 Code
type Tuple = [string, ...number[]];
type TupleIntersection = Tuple & { prop: string };


type TupleRestAccess = Tuple[1];
//   ^ number

type TupleIntersectionRestAccess = TupleIntersection[1];
//   ^ string | number


type TupleSpread = [...Tuple];
//     ^ [string, ...number[]]

type TupleIntersectionSpread = [...TupleIntersection];
//   ^ (string | number)[]
🙁 Actual behavior

TupleIntersection[1] and [...TupleIntersection] both seem to use an overly broad type, matching the number index signature instead of the more narrow spread signature.

What I mean is that TupleIntersection[1] behaves just like Tuple[number] does. This leads me to believe that the number index signature is synthesized correctly but the logic for numeric literals in the range of the spread signature aren't handled.

🙂 Expected behavior

I expected Tuple's behaviour to match TupleIntersection.

Additional information about the issue

No response

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

Inizia dalla riproduzione collegata in TypeScript Playground e confronta i risultati mostrati dell’accesso indicizzato e dello spread per Tuple rispetto a TupleIntersection. Traccia i punti di ingresso del compilatore che gestiscono le intersezioni di tuple, l’accesso tramite literal numerici e gli spread di tuple; il lavoro è completo quando l’intersezione conserva il comportamento di spread più restrittivo della tupla e la riproduzione corrisponde ai tipi previsti.

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.