Skip to content

Flatten Function Parameters and remember param names? #35752

Closed
@luky1984

Description

@luky1984

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)

type Flatten<T extends E[], E extends any[] = any[]> = {
  [K in keyof T]: T[K][Exclude<keyof T[K], keyof any[]>]
}

const a = (x: string) => { }

const c = (...args: Parameters<typeof a>) { }
const d = (...args: Flatten<[Parameters<typeof a>]) { } // later here can be Flatten<[Tuple1, Tuple2]> only one for now.

c() // arguments are: x:string
d() // argumentes are: args_0:string

Best would be something like this

const e = (...args: [...Parameters<typeof a>]) { }

https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=11&pc=4#code/C4TwDgpgBAYgNgQ2MCA7APAFShAHi1AEwGcoBRAbQF0AacnfNEqBVEaqAXhbeoD4uUAN4AoKFAoBpKAEtUUANYQQAewBmUTFQBcmqVQplcAYzgBXQhHRLVGzPro31PdlT5URAXxEjjK1MTALIIAFLi6gQBOcgDmAJRcAkJQ3r7+gVDGoQB0uQiRMcS6AAr5CAC2ECiRxOigkM4IfAnJ3n4BQYQ5eQVFsIjIaOgUpZEVVRA1deAQje4tKT7GIXEihCtAA

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions