Let's analyze the scenario below
type MergeFn = <K1 extends string, V1, K2 extends string, V2>(
k1: K1, v1: V1,
k2: K2, v2: V2
) => ???
let mergeFn: MergeFn // actual implementation doesn't matter for this question
What should be replaced in place of ???
so that
mergeFn(
"hello", 1,
"typescript", 2
)
results in
{ hello: number, typescript: number }
.
I attempted to use
??? = { [k in K1]: V1 } & { [k in K2]: V2 }
however, it only yields
{ hello: number } & { typescript: number }
.
(Even applying
type Id<T> = { [k in keyof T]: T[k] }
as suggested here did not provide a solution.)