I assume you are familiar with TypeScript mapped types and type inference.
In this article I will try to show you the power of static validation in TypeScript.
Let's start from a small example to better understand the approach. Imagine we have a function which expects some css width
value. It may be 100px
, 50vh
or 10ch
. Our function should do anything with argument, because we are not interested in business logic.
The naive approach would be to write this:
const units = (value: string) => { }