microsoft / microsoft/TypeScript

Signatures with less parameters aren't assignable to compatible targets with more when their rest param is an instantiated `NoInfer`

Abierto
#59,668 2 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Domain: check: Type Inference Help Wanted Possible Improvement
Lenguaje dominante
Go
Estrellas
111k
Forks
14.4k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

🔎 Search Terms

NoInfer signature parameters list rest

🕗 Version & Regression Information
  • This is the behavior in every version I tried
⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.6.0-dev.20240817#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXzCgggB4BBeEADwxFWAGd44pg8IBPeNAa1RwDuqANoBdAHwAKAFDx4sAOYAueJIB0GxQxUA5HAElUiEDHLiAlPAC84+ADccWYABpZ8DWq0qy0894Dc0mB4DBjwWEYmcMDWBEQQkpJQKqjIALYARiaWNvAA3gC+zvAAjMUATOaBAPTVcvUNjfAAegD80tKgkLAIKOjYeHHE5eSUNHSMzCCs7Fy8-EJiUm6KKuqaMAra8GQ5tg5OrnIeXju+AUEhYRHGMNHlsYTDJMKpmSbFb1kwEonJ8F9stZbIVimV4JUanV6m1pEA

💻 Code
declare function call<A extends readonly unknown[]>(
  arg: (...args: NoInfer<A>) => void,
  ...args: A
): A;

// Argument of type '(a: number) => void' is not assignable to parameter of type '(...args: NoInfer<[number, number]>) => void'.
//   Types of parameters 'a' and 'args' are incompatible.
//     Type '[number, number]' is not assignable to type '[a: number]'.
//       Source has 2 element(s) but target allows only 1.(2345)
const inferred = call((a: number) => {}, 1, 2);
//               ^? function call<[number, number]>(arg: (...args: NoInfer<[number, number]>) => void, args_0: number, args_1: number): [number, number]


declare function call2<A extends readonly unknown[]>(
  arg: (...args: A) => void,
  ...args: A
): A;
const inferred2 = call2<[number, number]>((a: number) => {}, 1, 2);
//    ^? const inferred2: [number, number]
🙁 Actual behavior

The first call fails to typecheck

🙂 Expected behavior

Both of those calls use the same arguments. The first one is using NoInfer so the covariant inference can get prioritized. That prevents the instantiated signature from typechecking like the second one. Note that the first call infers the same type argument as the one that is supplied explicitly to the second call: [number, number]

Additional information about the issue

I think that this can be fixed by normalizing NoInfer<[A, B]> to [NoInfer<A>, NoInfer<B>]. This would be similar to what instantiateMappedTupleType does today at times.

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 las dos llamadas usando una tupla NoInfer instanciada. Rastrea cómo el checker gestiona NoInfer en la asignabilidad de tuplas y parámetros rest, especialmente el comportamiento de normalización sugerido en el issue. Se considera terminado cuando tanto la llamada inferida como la llamada tipada explícitamente pasan la comprobación de tipos con la tupla esperada [number, number].

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
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
42/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.