34857-medium-defined-partial-record

Back

type DefinedPartial<T, K extends keyof T = keyof T> = K extends unknown
  ? T | DefinedPartial<Omit<T, K>>
  : never;

Solution by alexandroppolus #35291

type DefinedPartial<T extends Record<PropertyKey, unknown>> = Helper<keyof T, T[keyof T]>

type Helper<K, V, Keys = K> = [K] extends [never]
  ? never
  : Record<K & PropertyKey, V> | (K extends K ? Helper<Exclude<Keys, K>, V> : never)

Solution by Sun79 #35277

type DefinedPartial<T, K = keyof T> = K extends K ? T | DefinedPartial<{[P in Exclude<keyof T, K>]: T[P]}> : never;

Playground

Solution by teamchong #35276