How to type the merge of two types

Hello, I would like to type this typescript expression into rescript:

let mergeObjects = <S1 extends object, S2 extends object>(a: S1, b: S2): S1 & S2 => ({ ...a, ...b })

is this possible?

Kind of:

type s1 = {"a": string, "b": int}
type s2 = {"c": array<string>, "d": string}

let mergeObjects = (a: s1, b: s2): {...s1, ...s2} => Js.Obj.assign(a, b)

let mergedObject = mergeObjects({"a": "1", "b": 1}, {"c": [], "d": "2" })

Note that you can only use two spread operators in object types, but not in record types, nor objects or records. (Object | ReScript Language Manual)

1 Like

Thanks for your response, but I need this for generic types, something like this (using your example)

type mergeObjects<'s1, 's2> = (~a: 's1, ~b: 's2) => {...'s1, ...'s2}