microsoft / microsoft/TypeScript
Adding an overload to .filter breaks specific inference with nested functions
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
"filter inference overload", "filter boolean"
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about inferred types
⏯ Playground Link
💻 Code
type NonFalsy<T> = T extends false | 0 | "" | null | undefined | 0n
? never
: T;
// Comment this out
interface Array<T> { filter(predicate: BooleanConstructor, thisArg?: any): NonFalsy<T>[]; }
const id = <T,>() => (t: T) => !!t;
['foo', 'bar'].filter(id())
// ^?
🙁 Actual behavior
Nested function inference works (type parameter is string) without the additional overload, and fails (type parameter is unknown) with the overload (even though the added overload isn't the one in use).
🙂 Expected behavior
Nested function inference should work regardless of whether an overload is added to .filter or not.
Additional information about the issue
Adding the overload is described in https://github.com/microsoft/TypeScript/issues/50387 and made popular by ts-reset.
It's possible the overload order may matter in this instance, but difficult to test when the main overloads are coming from lib definitions.
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
Reproduce el comportamiento en el TypeScript Playground enlazado, comparando la inferencia con y sin la sobrecarga añadida de Array.filter BooleanConstructor. Lee las definiciones de lib relevantes y el contexto del orden de las sobrecargas del issue #50387; se considera terminado cuando la inferencia de funciones anidadas sigue infiriendo string para el ejemplo cuando la sobrecarga está presente.
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