Skip to content

Get another function's parameter types for use in another function's rest parameterΒ #58991

Closed

Description

@STofone

πŸ”Ž Search Terms

Rest parameter

πŸ•— Version & Regression Information

TypeScript Version 5.5.2

⏯ Playground Link

No response

πŸ’» Code

type AnyFunction = (...args: any[]) => any;
interface TestService {
  [key: string]: {
    [key: string]: AnyFunction;
  };
}
declare function f<S extends keyof TestService , F extends keyof TestService[S], A extends Parameters<TestService[S][F]>>(k1: S, k2: F, ...args: A): void;

πŸ™ Actual behavior

❌report at A : Rest parameter must be an array type or a generic with array constraint

πŸ™‚ Expected behavior

It can infer another function's params tuple as a rest param type

Additional information about the issue

#29919 seems similar
found in stackoverflow https://stackoverflow.com/questions/76772628/get-another-functions-parameter-types-for-use-in-another-functions-rest-par

Activity

  1. MartinJohns commented on Jun 24, 2024

    @MartinJohns
    Contributor

    You forgot to fill out the issue template completely.

    The code does not show any error in the playground.

  2. STofone commented on Jun 24, 2024

    @STofone
    Author

    same code in idea
    image
    image

    I tried in ts playground, it works fine.
    image
    ts playground
    may be is a problem of idea

  3. STofone commented on Jun 24, 2024

    @STofone
    Author

    image
    image
    image
    image
    Weird difference between each way of function definition inside object

  4. MartinJohns commented on Jun 24, 2024

    @MartinJohns
    Contributor

    Weird difference between each way of function definition inside object

    Properties and methods have different variance when strictFunctionTypes is enabled. And functions and lambdas have different this context.

  5. STofone commented on Jun 25, 2024

    @STofone
    Author

    Properties and methods

    playground
    I understand the different this context, but it seems has no difference of input param types.
    And it works fine in playground.

  6. 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions