Skip to content

Generic callback functions and 'this' #1568

@DanielAdolfsson

Description

@DanielAdolfsson
/** @noSelf */
declare namespace Test {
  export function testCallback<T extends (...args: any[]) => void>(
    callback: T,
  ): FunctionContainer<T>;
}

testCallback(() => {});

This fails with error TSTL: Unable to convert function with a 'this' parameter to function 'callback' with no 'this'. To fix, wrap in an arrow function, or declare with 'this: void'..

validateFunctionAssignment fails here. I could make it work by returning immediately if toType.isTypeParameter() is true, but I suspect that's not the correct solution to this particular problem.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions