Skip to content

Latest commit

 

History

History
34 lines (24 loc) · 810 Bytes

File metadata and controls

34 lines (24 loc) · 810 Bytes

Home > types-kit > ConditionalPick

ConditionalPick type

Pick by Condition (value).

Signature:

export type ConditionalPick<T, Condition, Exact extends boolean = false> = Pick<
  T,
  ConditionalKeys<T, Condition, Exact>
>

References: ConditionalKeys

Example

 interface Props {
      a?: number
      b: string
      c: boolean
    }

 // Expect: { a?: number, c: boolean }
 type NewProps = ConditionalPick<Props, number | boolean>
 // Set exact true, expect: { c: boolean }
 type NewProps2 = ConditionalPick<Props, number | boolean, true>