Skip to content

Bind does not preserve function return type #16796

Closed
@Jameskmonger

Description

@Jameskmonger

TypeScript Version: 2.4.0

Code

function foo<T>(provider: () => T): T { return undefined; }
function giveMeTrue(): boolean { return true; }

const okay: boolean = foo(giveMeTrue); // okay
const notOkay: boolean = foo(giveMeTrue.bind(this)); // type '{}' is not assignable to type 'boolean'

Expected behavior:

Both should be okay - bind does not change the return type of the function.

Actual behavior:

bind changes the function return type to any.

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