jtwang7 / JavaScript-Note

JavaScript学习笔记
10 stars 2 forks source link

DeepRequired & DeepPartial #78

Open jtwang7 opened 1 year ago

jtwang7 commented 1 year ago

DeepRequired & DeepPartial

自定义类型:

DeepRequired

export type DeepRequired<T> = T extends object
  ? Required<
      {
        [P in keyof T]: DeepRequired<T[P]>;
      }
    >
  : T;

DeepPartial

export type DeepPartial<T> = T extends object
  ? Partial<
      {
        [P in keyof T]: DeepPartial<T[P]>;
      }
    >
  : T;