Skip to content

Adding an overload to .filter breaks specific inference with nested functions #56013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
EskiMojo14 opened this issue Oct 6, 2023 · 0 comments Β· May be fixed by #56373
Open

Adding an overload to .filter breaks specific inference with nested functions #56013

EskiMojo14 opened this issue Oct 6, 2023 · 0 comments Β· May be fixed by #56373
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@EskiMojo14
Copy link

πŸ”Ž 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

https://tsplay.dev/wQbrvN

πŸ’» 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 #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.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Oct 6, 2023
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Oct 6, 2023
craigphicks added a commit to craigphicks/TypeScript-cph that referenced this issue Nov 12, 2023
craigphicks added a commit to craigphicks/TypeScript-cph that referenced this issue Nov 12, 2023
@craigphicks craigphicks linked a pull request Nov 12, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
2 participants