All files / types deep-partial.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17                                 
/**
 * Makes every property optional, at every depth: a patch of a nested settings object, read-only since a
 * patch is only read. Functions are kept whole; array items are deeply partial.
 *
 * @template T - The type to loosen.
 * @example
 * type SettingsPatch = DeepPartial<Settings>;
 * const patch: SettingsPatch = { chart: { grid: { isVisible: false } } };
 */
export type DeepPartial<T> = T extends (...arguments_: readonly never[]) => unknown
  ? T
  : T extends readonly (infer Item)[]
    ? readonly DeepPartial<Item>[]
    : T extends object
      ? { readonly [K in keyof T]?: DeepPartial<T[K]> }
      : T;