microsoft / microsoft/TypeScript
The intersection of a tuple with an unrelated array is handled inconsistently
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Bug Report
🔎 Search Terms
tuple, intersection, array, unrelated, narrowing, index signature
🕗 Version & Regression Information
This is the behavior in every version I tried
⏯ Playground Link
Playground link with relevant code
💻 Code
/* unrelated array */
type ShouldBeNever = string[] & [1, 2, 3]
type OK = (ShouldBeNever)[number] // never
type NotOK = (ShouldBeNever)[1] // 2
type WeirdOverload = (ShouldBeNever)['pop'] // {
// (): string | undefined
// (): 3 | 1 | 2 | undefined
//}
const isString = ([1, 2, 3] as ShouldBeNever).pop() // string | undefined
/* related array but not a supertype */
type ShouldBeNarrowed = [number | string, number | boolean] & (string | boolean | symbol)[]
type FF = ShouldBeNarrowed[number] // string | boolean
type HH = ShouldBeNarrowed[0] // string | number
🙁 Actual behavior
The index signature is appropriately updated, but not the individual elements nor the methods operating on the resulting tuple. Additionally, methods get overloaded, so when calling pop for example, the first overload is selected and the return type is not the intersection of the original components return types as it should be.
🙂 Expected behavior
I would expect ShouldBeNever to be [never, never, never] and ShouldBeNarrowed to be [string, boolean]
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 il TypeScript Playground collegato e riproduci i risultati di indexed access e dei metodi degli array per ShouldBeNever e ShouldBeNarrowed. Traccia come le intersezioni di tuple aggiornano le firme degli indici, i tipi degli elementi e i metodi; il lavoro è completo quando gli esempi producono i tipi di tupla never e ristretti attesi senza risultati incoerenti degli overload.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100