How Stronger TypeScript Types Eliminate Impossible Application States
A developer building a TypeScript vertical slice for a company write operation discovered a key insight about application service design. The repository layer returns `Company | undefined`, which is appropriate at the data level since a query can succeed even when a row is missing. However, the application service translates that `undefined` into an explicit not-found result, making the undefined state impossible beyond that layer. Retaining `Company | undefined` in the service's return type would force callers to handle a state the service has already resolved. The takeaway is that well-designed TypeScript types should encode use-case guarantees rather than expose lower-level uncertainties from the data layer.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in