microsoft / microsoft/TypeScript

The intersection of a tuple with an unrelated array is handled inconsistently

Abierto
#53,355 13 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Experimentation Needed Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.4k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

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]

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con el TypeScript Playground enlazado y reproduce los resultados de indexed access y de los métodos de arrays para ShouldBeNever y ShouldBeNarrowed. Rastrea cómo las intersecciones de tuplas actualizan las firmas de índice, los tipos de elementos y los métodos; se considera terminado cuando los ejemplos producen los tipos de tupla never y estrechados esperados sin resultados de sobrecargas inconsistentes.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
compilers
Tipo de issue
Error
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.