Browse Source

types: 添加 `Exclusive` 类型互斥语法糖

xiaoxian521 1 year ago
parent
commit
5f3210f69e
1 changed files with 4 additions and 0 deletions
  1. 4 0
      types/index.d.ts

+ 4 - 0
types/index.d.ts

@@ -41,6 +41,10 @@ type DeepPartial<T> = {
   [P in keyof T]?: DeepPartial<T[P]>;
 };
 
+type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
+
+type Exclusive<T, U> = (Without<T, U> & U) | (Without<U, T> & T);
+
 type TimeoutHandle = ReturnType<typeof setTimeout>;
 
 type IntervalHandle = ReturnType<typeof setInterval>;