Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 1.03 KB

File metadata and controls

38 lines (28 loc) · 1.03 KB

Home > types-kit > ReplacePick

ReplacePick type

Create a type that replace the values in the corresponding keys.

Signature:

export type ReplacePick<
  T,
  KeysArr extends readonly Keys<T>[],
  ValuesArr extends Fill<KeysArr['length'], unknown>,
> = {
  [P in keyof T]: InternalReplacePickValue<P, T[P], KeysArr, ValuesArr>
}

References: Keys, Fill, InternalReplacePickValue

Example

interface Props {
      readonly a?: {
        d?: boolean
      }
      b?: number
      c: number
   }

   // Expect: { readonly a?: number, b?: number, c: string }
   // ['a.d','c'] means the keys to replace, [string, string] means the values to map
   type new Props = DeepReplacePick<Props, ['a','c'], [number, string]>