All the code in this article has been tested with typescript 2.7.2 Sometimes, the base types offered by TypeScript, like number or string, are not enough to express precisely what you want. For example, you may want to represent the age of a user with a type indicating that it…