Repository navigation
Flatten Function Parameters and remember param names? #35752
Description
Activity
Questions like "how can I do this" do not belong here; try Stack Overflow instead. If you're requesting a feature or filing a bug then there are templates you should fill out, including some fields showing that you've done some of the initial research finding any existing issues that relate to your bug/request.
Tuples inferred from rest parameters, as implemented in #24897, will hold onto the parameter names as some metadata associated with the tuple type itself. Once you pull elements out of the tuple and re-wrap into a new tuple, you've thrown away the original tuple type and the metadata with it:
function f(x: string) { } type ForgetParamName<T extends (arg: any) => any> = (...blah: [Parameters<T>[0]]) => ReturnType<T>; type ForgottenF = ForgetParamName<typeof f>; // type ForgottenF = (blah_0: string) => void
There are ways to manipulate tuple types without losing this metadata, like mapping over them:
type Numberify<T extends any[]> = Extract<{ [K in keyof T]: number }, any[]>; type ToNumberParams<T extends (...args: any) => any> = (...args: Numberify<Parameters<T>>) => ReturnType<T> type RememberedF = ToNumberParams<typeof f>; // type RememberedF = (...x: number) => void
or converting back and forth to function parameter lists:
type PrependParam<T extends (...args: any) => any> = (addedParam: number, ...args: Parameters<T>) => ReturnType<T> type AlsoRememberedF = PrependParam<typeof f>; // type AlsoRememberedF = (addedParam: number, x: string) => void
But that's about it... arbitrary manipulation of tuples is likely to lose this information. If you're asking about adding some feature to deal with this, you should fill out the template and try to locate existing related issues, such as maybe #28259. Cheers!
Reacted by Luky and Martin JohnsReacted by LukyReacted by LukyReacted by LukyThank you its nice, but its not allowing to spread Tuple1 together with Tuple2 and make new params, only adding new single param. It is interesting still, but not fixing the problem.
This isn't a forum for fixing problems... if you are making a feature suggestion, such as "concatenate tuple types while preserving parameter names", there is a template you should fill out, along with search terms and related issues. (Note, possibly related to #5453, which doesn't explicitly mention parameter names).
Reacted by Martin Johns- addedQuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
on Dec 18, 2019 RyanCavanaugh commented
on Dec 18, 2019 MemberMore actionsTo expedite the triage process, we need everyone to follow the issue template and instructions.
When you clicked "Create New Issue", the issue form was pre-populated with a template and some instructions. We need you to read those instructions completely, follow them, and then fill in all the fields in that template.
We are not able to assist with issues that don't follow the template instructions as they represent a significantly larger amount of work compared to issues which are correctly specified. Thank you for understanding.
- locked as resolved and limited conversation to collaborators
on Oct 21, 2025
I would like to create new tuple of function params A and B.. that means flatten together two function params. I have the flatten type for that. For sake of simplicity showing only with one Parameters not two below.
But problem is that Typescript then forgets the parameter names, would it be possible to fix it somehow? Neither is possible to extract the params names from Parameters<> helper. (just saying another not related problem)
https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=11&pc=4#code/C4TwDgpgBAYgNgQ2MCA7APAFShAHi1AEwGcoBRAbQF0AacnfNEqBVEaqAXhbeoD4uUAN4AoKFAoBpKAEtUUANYQQAewBmUTFQBcmqVQplcAYzgBXQhHRLVGzPro31PdlT5URAXxEjjK1MTALIIAFLi6gQBOcgDmAJRcAkJQ3r7+gVDGoQB0uQiRMcS6AAr5CAC2ECiRxOigkM4IfAnJ3n4BQYQ5eQVFsIjIaOgUpZEVVRA1deAQje4tKT7GIXEihCtAA