Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
STofone opened this issue Jun 24, 2024 · 5 comments

Comments

@STofone
Copy link

STofone commented Jun 24, 2024

πŸ”Ž 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

@MartinJohns
Copy link
Contributor

You forgot to fill out the issue template completely.

The code does not show any error in the playground.

@STofone
Copy link
Author

STofone commented Jun 24, 2024

same code in idea
image
image

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

@STofone STofone closed this as completed Jun 24, 2024
@STofone
Copy link
Author

STofone commented Jun 24, 2024

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

@MartinJohns
Copy link
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.

@STofone
Copy link
Author

STofone commented Jun 25, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants