types-kit.conditionalomit.md

September 4, 2023 ยท View on GitHub

Home > types-kit > ConditionalOmit

ConditionalOmit type

Omit by Condition (value).

Signature:

export type ConditionalOmit<
  T,
  Condition,
  Exact extends boolean = false,
> = StrictOmit<T, ConditionalKeys<T, Condition, Exact>>

References: StrictOmit, ConditionalKeys

Example

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

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