Home > front end >  typescript extract record from union
typescript extract record from union

Time:10-12

i have this union of records

type PhysicalEntry = Record<
    'color' | 'luster' | 'name' | 'quantity' | 'status' | 'type',
    {
      value: string | number
      hasCheck: boolean
      readOnly: boolean
    }
  > &
    Record<
      'customData',
      {
        values: Array<number>
        hasCheck: boolean
        readOnly: boolean
      }
    >

how do i extract the first record by excluding PhysicalEntry['customData']?

CodePudding user response:

You can use the Omit helper type.

type WithoutCustomData = Omit<PhysicalEntry, "customData">

TypeScript will expand the rest of the properties, but the shape will be correct.

  • Related