Skip to content

Cannot infer generics through n>=2 functions of an argumentΒ #53748

@alii

Description

@alii

Bug Report

πŸ”Ž Search Terms

arguments, generics, inference, two or more, variance

πŸ•— Version & Regression Information

  • This changed between versions 4.7 and 4.8+ (stopped working on 4.8+)

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

declare type Callback<Args extends any[], Out, R> = (...args: Args) => (data: Out) => R;
declare function factory<Out>(): <Args extends any[], R>(callback: Callback<Args, Out, R>) => (...args: Args) => R;

const make = factory<{id: string, age: number}[]>();

// Errors here
const usersOverAge = make((age: number) => data => {
    return data.filter(user => user.age >= age);
});

πŸ™ Actual behavior

The code errors with a function not being assignable to a signature, and generics not being inferred correctly.

πŸ™‚ Expected behavior

The function definition is passed as expected and generics are correctly inferred

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions