Restricting a Typescript Type to a Set of Numbers

--

Image by Pexels from Pixabay

Scenario

We need a Typescript type that restricts a Quadrant to the numbers 1,2,3,4.

Approach

type Quadrant = 1 | 2 | 3 | 4;

Demo

--

--

Ole Ersoy

Founder of Firefly Semantics Corporation