Typescript学习: Omit 与 Pick
typescript的2个常用工具
基本理解
Omit基本用法
type SuperbUser = {
userId: number,
macAddress: string,
username: string,
email: string,
password: string,
firstName: string,
lastName: string,
roles: ('Admin' | 'Editor' | 'Author')[]
};
type Subscriber = Omit<SuperbUser, 'roles'>;
Pick基本用法
interface SuperbUser {
userId: number;
macAddress: string;
username: string;
email: string;
password: string;
firstName: string;
lastName: string;
roles: ('Admin' | 'Editor' | 'Author')[]
};
type GuestUser = Pick<SuperbUser, 'userId' | 'macAddress' | 'username'>;
参考