Skip to content

Difference in parameter inference between arrow functions and classic functions #50258

Description

In the example code below the arrow function has correct type inference while the function example is unable to infer the parameter type and falls back to any.

declare function monitor<T extends (...args: any) => any>(
  extractor: (...args: Parameters<T>) => Record<string, unknown>,
  executor: T,
): (...args: Parameters<T>) => ReturnType<T>;

monitor((p) => ({ p }), (p: number) => p);
monitor((p) => ({ p }), function (p: number) { return p; });

image

image

Activity

  1. knutkj commented on Aug 10, 2022

    @knutkj
    Author

    Note that if we specify type of this (this: void) the function variant is also able to infer the type:

    image

  2. RyanCavanaugh commented on Aug 10, 2022

    @RyanCavanaugh
    Member

    Duplicate #47599

  3. typescript-bot commented on Aug 13, 2022

    @typescript-bot
    Contributor

    This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  4. locked as resolved and limited conversation to collaborators on Oct 22, 2025
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

    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