In TypeScript, the narrower the type, the more safety and clarity we have
In TypeScript, the narrower the type, the more safety and clarity we have.
So if a PR widens a type, that’s a code smell.
When this happens, I ask:
- Is the type needlessly wide? (For instance, I often see needless optional fields)
- Could we use a discriminated union to support two or more narrower types?
- Should we create two separate implementations that each use a narrower type?