Better typings for strings and numbers in TypeString using opaque types

Kacper Kula
hypersphere
Published in
5 min readApr 25, 2022

--

Opaque types in TypeScript

TypeScript is a great tool to ensure your code is correct and you are not passing incorrect data around. Unfortunately, there are still cases when we can’t guarantee that the types are correct — especially when dealing with primitives like strings or numbers.

In almost every modern application we use strings to represent a bunch of different…

--

--