microsoft / microsoft/TypeScript
Empty rest parameter type inferred from candidate function with no rest parameters when "best match" contains a contextually typed argument
Nadie ha tomado este issue todavía.
- 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
Rest parameter inference contextual
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about type inference
⏯ Playground Link
Playground link with relevant code
💻 Code
const doSomething = <Args extends unknown[]>(
fn1: (aNumber: number, ...rest: Args) => void,
fn2: (aNumber: number, ...rest: Args) => void,
) => {}
// OK, no contextual types
doSomething(
(explicit: number, rest: string) => {}, // Args = [string]
() => {},
)
// OK (both contain contextually typed arg)
doSomething(
(contextual, rest: string) => {}, // Args = [string]
(contextual) => {},
)
// Contextually type only fn1 - Not ok
doSomething(
(contextual, rest: string) => {}, // ERROR
() => {}, // Args = []
)
doSomething(
(contextual, rest: string) => {}, // ERROR
(explicit: number) => {}, // Args = []
)
🙁 Actual behavior
When fn1 (and only fn1) contains a contextually typed argument, it is ignored in favour of fn2
🙂 Expected behavior
In all of the examples, fn2 specifies no rest parameters at all.
I would expect functions that do not specify any rest parameters to always be the least preferable candidate (lowest weight?) for rest parameter inference, since "no rest parameters" can always be assigned to any rest parameter type.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con la reproducción enlazada de TypeScript Playground y reduce las tres llamadas a doSomething para aislar cómo el tipado contextual afecta a la inferencia de parámetros rest. Sigue la ruta de comprobación de tipos que selecciona los candidatos de inferencia y después añade una prueba de regresión para los casos mostrados; terminado cuando el tipo rest [string] de fn1 no sea reemplazado por [] de fn2.
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
- Bien especificado
- Aptitud para principiantes
- 35/100