Skip to content
Berktug Berke Ates
Berktug Berke Ates

Software Engineer

Blogs

Typed Boundaries in Modern TypeScript Systems

· 7 min read

TypeScript pays off when types protect the seams between modules, APIs, and runtime data.

Types are strongest at the edges

Internal function annotations help, but the expensive bugs usually cross process, network, storage, or team boundaries. Invest typing effort where untrusted or independently deployed data enters the system: HTTP payloads, queue messages, environment configuration, and third-party webhooks.

At those edges, compile-time types are not enough. Pair them with runtime schemas so invalid data fails in a controlled way before it corrupts domain logic.

Share contracts, not implementations

Generate or publish shared types for clients and servers from a single source of truth. Keep transport details and UI concerns out of the domain model. A change to a field's nullability should be deliberate and visible to every consumer.

Branded types for identifiers prevent accidental mixing of user IDs, organization IDs, and external references. Small nominal distinctions catch an entire class of integration mistakes.

  • Validate on read at trust boundaries
  • Make illegal states unrepresentable where cheap
  • Prefer explicit result types over thrown ambiguity
  • Keep DTOs separate from persistence models

Avoid type theater

Overfitting types to every temporary UI state creates churn without safety. Escape hatches such as any, broad casts, and overly clever conditional types should be rare and justified. Readable types that teammates can change are more valuable than ingenious ones nobody understands.

Measure success by fewer production parsing errors and safer refactors, not by the density of generics.

Let types document decisions

A good type system captures product rules: which fields exist after onboarding, which statuses allow refunds, which payloads are versioned. That documentation stays honest because the compiler enforces it.

TypeScript is most effective when it encodes the architecture you already believe in, then prevents the team from accidentally abandoning it.


Published on September 30, 2025 by Berktug Berke Ates.