Single Source of Truth

What

A “Single Source of Truth” approach means defining each core entity type exactly once and deriving any necessary variations (like versions without IDs or with optional fields) from that original definition.

How

Instead of copy-pasting properties into new interfaces, you use inheritance or TypeScript’s transformation tools to build related types:

interface User {
  id: string;
  name: string;
  email: string;
}

// Derive a type for creating a new user (which doesn't have an ID yet)
interface NewUser extends Omit<User, 'id'> {}

Why

Defining types multiple times leads to “drift,” where one version of a type is updated but others are forgotten. By having a single source of truth, you ensure that a change to a core entity automatically propagates to all its derived types, making your codebase much easier to maintain and refactor.

Summary

Design your types so that every piece of information is defined in exactly one place.