Skip to content

Lack of type checking for callback parameters #15579

Closed

Description

@falsandtru

TypeScript Version: master

Code

function f(g: (ev: Event) => any) { }
function g(ev: MouseEvent) { }
f(g);
f(ev => g(ev));

Expected behavior:

$ node built/local/tsc.js index.ts --noEmit --strict
index.ts(3,3): error ...
index.ts(4,11): error TS2345: Argument of type 'Event' is not assignable to parameter of type 'MouseEvent'.
  Property 'altKey' is missing in type 'Event'.

Actual behavior:

$ node built/local/tsc.js index.ts --noEmit --strict
index.ts(4,11): error TS2345: Argument of type 'Event' is not assignable to parameter of type 'MouseEvent'.
  Property 'altKey' is missing in type 'Event'.

Activity

  1. added
    Question
    on May 5, 2017
  2. falsandtru commented on May 6, 2017

    @falsandtru
    ContributorAuthor

    I didn't know that well because the FAQ doesn't say specific definitions of types of Animal and Dog. But it seems like you can keep the consistency of f(g) and f(ev => g(ev)). Are you really choosing the current inconsistency?

  3. RyanCavanaugh commented on May 8, 2017

    @RyanCavanaugh
    Member

    Suffice to say we've thought about this problem a lot and are sticking with the current situation.

  4. added
    Fixed
    on Sep 21, 2017
  5. locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedQuestion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions