Skip to content

Possible bug when typing a function that receives a function and its parameters #16871

Closed
@leoasis

Description

@leoasis

TypeScript Version: 2.3.4

Code

interface Payload {
    a: string,
    b: number
}

let doFoo: (payload: Payload) => void;

let executeAction: <P>(
    action: (payload: P) => void, payload: P
) => void;


executeAction(doFoo, { a: 'hello', b: 2 }); //no errors, ok
executeAction(doFoo, {}); //no errors, wrong!
executeAction(doFoo, { qwe: 2 }); //errors, ok
executeAction(doFoo, { a: 'hola' }); //no errors, wrong!

doFoo({ a: 'hello', b: 2 }); //no errors, ok
doFoo({}); //errors, ok
doFoo({ qwe: 2 }); //errors, ok
doFoo({ a: 'hola' }); //errors, ok

Expected behavior:

The lines commented with "wrong!" should show errors.

Actual behavior:

Those lines don't show errors

I added the direct calls to doFoo at the bottom for clarification of what I'm expecting. If I'm doing something wrong please let me know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions