rest parameter
A final function parameter written ...args that collects all remaining arguments into an array.
In more detail
It must be the last parameter, and there can be only one. Typing it with a tuple, such as ...args: Parameters<F>, keeps each argument's type and position.
Example
return (...args: Parameters<F>): ReturnType<F> => fn(...args);Related terms
- spread syntax — The three-dot JavaScript syntax that copies the items of an array or the properties of an object into a new one.
- variadic tuple — A tuple type containing a spread such as [query: string, ...params: (string | number)[]], so its length can vary.
- Parameters<T> — The utility type that gives a function type's parameter list as a tuple, such as [orderId: string, priority: boolean].
Taught in
- Tuples: Fixed Length, Labeled Elements And Variadic Tuples — Production TypeScript
- Function Utilities: ReturnType, Parameters And Constructor — Production TypeScript
- Modern Decorators: Stage 3 Standards And Class Metadata — Production TypeScript