typescriptunionunion-types

How to merge union literaltypes


I have the following:

export type UHaem = 'haem.cbc' | 'haem.rbc'
export type UChem = 'chem.glucose' | 'chem.electrolytes'

How could I merge both to have the final type as shown below:

export type ULab = 'haem.cbc' | 'haem.rbc' | 'chem.glucose' | 'chem.electrolytes'

Solution

  • As simple as this:

    export type ULab = UHaem | UChem;