LLearnCode
Academy/typescript/Production TypeScript

advanced · 22 minute study

Type components around ownership

Good component types show who owns state, what events mean and which combinations of props are valid.

Loading progressEvidence grows with practice
Useful preparation · 1 prerequisite

Use this as a map, not a lock. If these ideas are familiar, continue.

  • Design away impossible states — Several independent booleans can describe contradictory states. A small explicit state machine makes transitions reviewable and testable.

First, build a mental model

Props are a public contract. Model relationships and valid combinations, rather than turning every field optional to make call sites quiet.

  1. A generic item type can connect data and selection callbacks.
  2. Controlled state receives a value and an update callback from its owner.
  3. Discriminated props make mutually exclusive modes explicit.
  4. Do not export broad any-shaped component interfaces just to avoid discussing ownership.
Read the codetypescript · educational example
type SelectProps<T> = { items: readonly T[]; selected: T | null; onSelect: (item: T) => void };
type ButtonAction =
  | { mode: 'link'; href: string }
  | { mode: 'action'; onActivate: () => void };
const link: ButtonAction = { mode: 'link', href: '/learn' };
const playerSelect: SelectProps<{ id: string }> = {
  items: [{ id: 'p1' }], selected: null,
  onSelect: player => console.log(player.id)
};
  1. Ownership

    selected belongs to the caller; the component reports intent through onSelect.

  2. Generic

    items and the callback agree on the same player shape.

  3. Mode

    The link variant requires href; action requires onActivate.

Production thinking

Take this beyond the example.

Keep reusable UI contracts independent of private domain internals. Test keyboard behavior and state transitions as well as prop assignability.

Sources and further reading

Your evidence

unseen is a local learning signal, not a credential or proof of production competence.

Explain the mental model, then explicitly acknowledge it. Opening a page is not evidence.

Supported retries can complete this lesson. Independent evidence and delayed review determine the skill stage.

Next lesson · Compiler settings are part of architecture →