Problem: Optional fields are overused in TypeScript


Problem: Optional fields are overused in TypeScript. Sometimes they’re applied when they’re not even necessary.

Solution: In code reviews, if the optional field seems needless, I make the field required, then see if the code compiles.

If the code compiles, we can eliminate the optional field.

If it doesn’t compile, I consider adding a default at call sites so we can require the field.

View original on X