Search This Blog

2023/09/10

TypeScript:Omit & Pick property in Type


 type MyUser = {
name: string;
age: string
id: string;
}
//omit multiple properties
type NewUser1 = Omit<MyUser, "id" | "age">

const newUser: NewUser1 = {
name: "sangram"
}

//pick multiple properties
type NewUser2 = Pick<MyUser, "id" | "age">

const newUser2: NewUser2 = {
id: "sangram",
age: "45"
}

No comments:

Post a Comment