我想知道它是否具有以下任何功能。我试过谷歌,但我无法找到它。谢谢!
interface Numbers {
number: number;
number2: number;
number3: number;
}
const numbers:Numbers - { number3 } = {
number: 1,
number2: 2
};
答案 0 :(得分:4)
您可以使用新的Exclude
条件类型和Pick
映射类型
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
interface Numbers {
number: number;
number2: number;
number3: number;
}
const numbers:Omit<Numbers, 'number3'> = {
number: 1,
number2: 2
};
在Omit
之前可以这样定义:
type Diff<T extends string, U extends string> = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T];
type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;