TypeScript型から特定のpropertiesを削除
するには、Pick<T, K extends keyof T>とExclude<U,E>を組み合わせる
code:ts
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
union (typescript)を使えば、複数のキーを消すこともできる
code:ts
type Hoge = {
foo: number;
bar: string;
baz: boolean;
};
type Fuga = Omit<Hoge, "foo" | "baz">;
// → { bar: string; }
References
Exclude<T, U>, Extract<T, U> | TypeScriptの型初級 - Qiita
#typescript
#2021-08-13 20:43:53
#2021-07-06 06:05:45