microsoft / microsoft/TypeScript
Adding an overload to .filter breaks specific inference with nested functions
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das Verhalten im verlinkten TypeScript Playground und vergleiche die Inferenz mit und ohne die hinzugefügte Array.filter BooleanConstructor-Überladung. Lies die relevanten lib-Definitionen und den Kontext der Überladungsreihenfolge aus Issue #50387; als erledigt gilt die Aufgabe, wenn die Inferenz verschachtelter Funktionen für das Beispiel weiterhin string inferiert, sobald die Überladung vorhanden ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100