Theo's Typesafe CultTTC
Theo's Typesafe Cult4y ago
3 replies
nanorise

Type to require elements of array to all have one property or the other

I'm looking for a type that will force all elements of the array to have 1 property or the other

example

interface ColumnCommon {
  id: string;
}


type WidthedColumn = ColumnCommon & { width?: Length; };
type WeightedColumn = ColumnCommon & { weight?: number; };

type Columns = Array<WidthedColumn> | Array<WeightedColumn> 


so here I need two things
1. one column can't have both weight and width
2. all columns in the array should have the same property (weight or width)
Was this page helpful?