Stronger application-layer types remove impossible states

작성자

카테고리:

← 피드로
DEV Community · LkSvn · 2026-07-19 개발(SW)
Cover image for Stronger application-layer types remove impossible states

LkSvn

Today I completed a small Company write vertical slice in TypeScript, from business validation to PostgreSQL persistence.

One detail clarified why application services are more than repository wrappers.

The repository update returns Company | undefined. That makes sense at the data layer: the query can succeed while the requested row does not exist.

But the application service translates undefined into an explicit not-found result.

After that translation, keeping Company | undefined in the successful return type would force every caller to handle a state the service has made impossible.

So the application contract returns either:

  • success with a Company
  • validation failure
  • not-found failure
  • repository failure

The type now describes the use-case guarantee instead of leaking the repository’s lower-level uncertainty.

The practical lesson:

good TypeScript types do more than prevent syntax mistakes. They help make invalid or impossible application states unrepresentable.

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다