TLDR Web Dev · ARTICLES & TUTORIALS

MAKE INVALID STATES UNREPRESENTABLE

links.tldr.tech11 min read

Summary from the TLDR Web Dev newsletter

Invalid states can lead to runtime errors and less reliable code. However, by shrinking the gap between representable, valid states, errors can be moved from runtime to compile time, which allows them to get caught much earlier. Type systems can and should be used to model business logic that makes invalid states impossible and unrepresentable. This article goes through a few examples, such as a “Color” type that prevents invalid colors.