Skip to content

Passing generic function as an argument fails compile #2081

Open
@endercrest

Description

@endercrest

It would seem that the compiler isn't resolving the type for a generic function that is being passed in as an argument where the type should be resolvable.

Example Code:

function freeFunction<T>(value: T): T {
  return value;
}

function bad<T>(value: T, func: (value: T) => T): T {
  return func(value);
}

export function test(): i64 {
  return bad<i64>(123, freeFunction);
}

WebAssembly Studio Example: https://webassembly.studio/?f=gpmwo8wi18h

Error:

ERROR TS2554: Expected 1 arguments, but got 0.

   return bad<i64>(123, freeFunction);
                        ~~~~~~~~~~~~
 in main.ts(10,24)

FAILURE 1 compile error(s)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions