Skip to content

Can not call a generic function as an call "effect" (pattern in in redux-saga) #40798

Closed
@kasperpeulen

Description

@kasperpeulen

TypeScript Version: 4.0.2

Code

interface Foo {
  bla: string;
}

declare function map<T, R>(value: T[], transform: (t: T) => R): R[];

declare const foos: Foo[];

declare function call<Fn extends (...args: any[]) => any>(
  fn: Fn,
  ...args: Parameters<Fn>
): ReturnType<Fn>;

const a = call(map, foos, (foo: Foo) => foo.bla);

Expected behavior:
I expect this to give no compile errors.

Actual behavior:

Argument of type '(foo: Foo) => string' is not assignable to parameter of type '(t: unknown) => unknown'. Types of parameters 'foo' and 't' are incompatible. Type 'unknown' is not assignable to type 'Foo'

Playground Link:
Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions