#Operating on tuples - how to preserve member types?

8 messages · Page 1 of 1 (latest)

merry craterBOT
#
onkeltem#0

Preview:```ts
import {ReactNode} from "react"

type FnCp<P = {}> = {(props: P): ReactNode}

function createMany<P1, P2>(
Comp1: FnCp<P1>,
Comp2: FnCp<P2>
): [FnCp<P1>, FnCp<P2>] {
return [Comp1, Comp2].map(comp => comp) as [
FnCp<P1>,
FnCp<P2>
]
}```

jolly shore
#

Hi folks. I need to make a function, which takes a tuple of components, calls a HOC against every member and returns the result

#

This is an implementation for only two components

#

and it's not good as map "loses" information about the tuple

#

so I have to use as [...,...] and "restore" the tuple

#

Is there a way to describe anything like this in TypeScript?

#

Say, using recursive calls or something

frail verge
#

mapped tuples?