microsoft / microsoft/TypeScript
Generic function with function as argument autocomplete broken, unless generic argument of the argument function is it's first 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
🔎 Search Terms
typescript generic function no autocomplete function as argument
🕗 Version & Regression Information
Relevant versions are 5.4.5 and above, tested in all versions from 5.4.5 to 5.8.0 (Nightly) inclusive, I was able to reproduce the bug in all versions.
⏯ Playground Link
💻 Code
async function registerPluginBad<Opt extends Record<string, any>>(callback: (app: any, options: Opt) => void, opts: NoInfer<Opt>): Promise<void> {}
registerPluginBad((app, opts: { something: string }) => {}, {
// below autocomplete is broken, even though the type is properly validated
some
});
// interestingly, autocomplete works if "options" argument comes first, for example:
async function registerPluginGood<Opt extends Record<string, any>>(callback: (options: Opt, app: any) => void, opts: NoInfer<Opt>): Promise<void> {}
registerPluginGood((opts: { something: string }, app: any) => {}, {
// below autocomplete works
some
});
🙁 Actual behavior
This one has to be tested in the playground:
registerPluginBad - second argument does not autocomplete, however type is properly validated
registerPluginGood - exact same function, except the first argument "callback" arguments have changed the order, which for some reason fixes the autocomplete
🙂 Expected behavior
For both functions, autocomplete should work. Argument order should not matter.
Both do not infer from "opts", so any inference should be from "options" argument of the callback.
Additional information about the issue
No response
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
Abre el TypeScript Playground enlazado y reproduce la diferencia entre registerPluginBad y registerPluginGood. Rastrea el comportamiento del autocompletado y la inferencia genérica para el orden de los parámetros del callback; el trabajo estará terminado cuando ambas llamadas proporcionen autocompletado para el objeto de opciones y mantengan la validación de tipos.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers, developer-experience
- 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