Skip to content

Generic function parameters seem to ignore typecheck #1073

Closed
@deplinenoise

Description

@deplinenoise

The type checker seems fine with this use of a generic type in a function parameter:

function callMe<T>(value: T, fn: (value: T) => void) : void {
  fn(value);
}

// No error!
callMe(17, (n: string) => console.log(n) );

If callMe is made non-generic and uses hardcoded types then an error is issued as expected:

function callMeConcrete(value: number, fn: (value: number) => void) : void {
  fn(value);
}

// Error as expected!
// TS2345: Argument of type '(n: string) => void' is not assignable to parameter of type '(value: number) => void'.
callMeConcrete(17, (n: string) => console.log(n) );

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions