majkl zumberi
majkl zumberi

Reputation: 180

typescript extract record from union

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']?

Upvotes: 0

Views: 108

Answers (1)

ddprrt
ddprrt

Reputation: 7574

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.

Upvotes: 1

Related Questions