TypeScript標準にDiff型がないけどExcludeという名前で同じ機能
ここのハンドブックに紹介されているDiff型は、標準にないので自分でコピペして使う感じになる。
でもDiffは使うごとにコピペするのはあまり好ましくないので、探してみるとExcludeという名前で存在している。
以下のDiffとExcludeの型を見てわかるように同じ定義。
code:ts
type Diff<T, U> = T extends U ? never : T; // Remove types from T that are assignable to U
code:ts
/**
* Exclude from T those types that are assignable to U
*/
type Exclude<T, U> = T extends U ? never : T;
知ったきっかけ