Merge two types into a new type. Keys of the second type will override keys of the first type.
Signature:
export type Merge<A, B> = A extends readonly unknown[]
? B extends readonly unknown[]
? MergeTuple<A, B>
: Simplify<
StrictOmit<A, Extract<Keys<A>, Keys<B>>> & {
[P in keyof B as P extends Keys<B> ? P : never]: B[P]
}
>
: Simplify<
StrictOmit<A, Extract<Keys<A>, Keys<B>>> & {
[P in keyof B as P extends Keys<B> ? P : never]: B[P]
}
>References: MergeTuple, Simplify, StrictOmit, Keys
interface Foo {
a: number;
b: string;
};
interface Bar {
b: number;
};
// Expect: { a: number, b: number }
type NewProps = Merge<Foo, Bar>