We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Parameters
TypeScript Version: 3.7.5
Search Terms: function parameters spread
Expected behavior: Expected the playground example to compile without errors
Actual behavior: The code works great, but Typescript throws the following error:
Type 'Parameters' must have a 'Symbol.iterator' method that returns an iterator. (2488)
Code
export function call<F extends (...args: any) => any>( fn: F, ...parameters: Parameters<F> ): ReturnType<F> { return fn(...parameters); }
Playground Link: Provided
The text was updated successfully, but these errors were encountered:
As a workaround, ...args: [...Parameters<T>] works.
...args: [...Parameters<T>]
Sorry, something went wrong.
Use (...args: any[]) => any and it'll work: Playground
(...args: any[]) => any
On a tangent, IMO, this looks a bit classier:
function call<F extends (...args: any[]) => any, P extends any[] = Parameters<F>, R = ReturnType<F>>( fn: F, ...parameters: P ): R { return fn(...parameters); }
I'm still uncertain of how to achieve that in strict mode though.
As mentioned by @AlCalzone in #41728, this seems to work when replacing any with any[].
any
any[]
No branches or pull requests
TypeScript Version: 3.7.5
Search Terms:
function parameters spread
Expected behavior:
Expected the playground example to compile without errors
Actual behavior:
The code works great, but Typescript throws the following error:
Code
Playground Link: Provided
The text was updated successfully, but these errors were encountered: