microsoft / microsoft/TypeScript
Adding an overload to .filter breaks specific inference with nested functions
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci il comportamento nel TypeScript Playground collegato, confrontando l’inferenza con e senza l’overload aggiunto Array.filter BooleanConstructor. Leggi le definizioni lib pertinenti e il contesto dell’ordine degli overload dall’issue #50387; il lavoro è completato quando l’inferenza delle funzioni annidate continua a inferire string per l’esempio quando l’overload è presente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100