UPDATE
i stumbled upon this solutiontype Merge<T, U> = { [K in keyof T | keyof U]: K extends keyof U? U[K]: K extends keyof T? T[K]: never; };
is there an equivalent in typescript using the spread operator?
type Merge<T, U> = ...[K in keyof T]: T[K], ...[K in keyof U]: U[K]
my objective is to combine two types into a new type. The keys of the second type will override keys of the first type. for example:
interface User {
id: string;
name: string;
age: number;
role: "admin" | "moderator" | "user";
occupation: string;
}
interface User2 {
id: string;
name: string;
age: boolean;
}
type mergedType = Merge<User, User2>
after merging, the interface type will look like this->
{
id: string;
name: string;
age: boolean;
role: "admin" | "moderator" | "user";
occupation: string;
}