React Forum
Blog & Guide Responses
Feb 08, 2023 · 04:00 AM

TypeScript: Everyday Types - discussion (2023-02-08)

Started by Soren Malik
externaltypescripteveryday typesunionsinterfacescontractslanesevidence

The "Everyday Types" chapter is the best reminder that the highest ROI types are the boring ones: small unions, stable shapes, and readable contracts. In React code, this often maps directly to lane objects, route state objects, and derived evidence shapes that multiple panels must agree on.

Read the handbook

What everyday types patterns have saved you most time in React apps (lanes, intent unions, route state)? How do you avoid types becoming "clever" and turning into a barrier to entry? Do you type your evidence/log vocabulary too, or keep logs as loose strings?

Comments (18)

Back to latest
Marisol Vega
Feb 11, 2023 · 11:11 AM

String unions for tabs/panels and discriminated unions for async lanes are the biggest wins.

They eliminate a whole class of impossible UI states.

Dmitri Kline
Feb 14, 2023 · 02:14 PM

We type the lane object and then derive a readable evidence line from it. The code is boring, which is why it's good:

ts
type Lane =
  | { kind: 'idle' }
  | { kind: 'pending'; startedAt: number; reason: string }
  | { kind: 'ok'; freshnessAt: string }
  | { kind: 'error'; message: string };

And the log line is stable vocabulary:

txt
[tips] lane=pending reason=route:enter
[tips] lane=ok freshnessAt=2023-02-14T14:14Z
Keira Santos
Feb 18, 2023 · 06:06 AM

Counterpoint: typing logs can become busywork if you try to type every string.

We type the *inputs* (lane, posture, intent) and keep the final log line as a string. It's still consistent because the inputs are typed.

Soren Malik
Feb 21, 2023 · 04:04 AM

Same. The goal is consistency, not bureaucracy.

Typed vocab + readable strings is a good compromise.

Grace McCoy
Mar 01, 2023 · 03:03 AM

Everyday types are also about *making refactors safe*.

If you tighten a union, the compiler shows every UI lane that needs to be updated. That is basically a correctness tool.

Jasper Nguyen
Mar 14, 2023 · 02:14 PM

Long-form: the more your app relies on stored-derived outputs, the more types become product reliability.

If your derived keys are misspelled, you ship contradictory UI. So we type derived shapes aggressively and keep them boring.

Nina Kapoor
Mar 29, 2023 · 03:03 AM

I like interfaces for durable contracts (doc shapes), unions for lanes and intent.

That mix keeps the codebase readable and keeps changes localized.

Camille Duarte
Apr 18, 2023 · 06:18 PM

We also typed route state defaults and it prevented drift between list and detail.

If defaults are typed and centralized, components can't invent their own idea of what the route means.

Owen Price
May 10, 2023 · 10:10 AM

Counterpoint: TS can become a false sense of safety if runtime boundaries are loose.

We still validate at boundaries and store validation results as derived evidence so the UI can be honest about it.

Benji Rios
Jun 01, 2023 · 06:06 AM

We used everyday types to model "posture" and it made debugging easier.

Instead of random booleans, you get a readable value you can render and log.

Lina Ortega
Jun 25, 2023 · 10:22 PM

Docs tie-in: TS types are the fastest way to enforce the vocabulary used in the docs and guides.

Related: TypeScript and Types and API Reference.

Amina Farouk
Jul 21, 2023 · 07:07 AM

We keep types simple by choosing names that match the product language (lane, posture, intent).

If the type names are abstract, people stop using them and start using any.

Evan Brooks
Aug 19, 2023 · 07:19 PM

Long-form counterpoint: some teams over-type and end up with types that require a PhD to change.

The handbook's tone is right: types should make code easier to read. If they're harder than the code, you lost.

Theo Bennett
Sep 18, 2023 · 12:12 PM

Typing "intent objects" was the best improvement for us. It made mutation handlers readable and testable.

And because intent is typed, logs become consistent too.

Priya Liao
Oct 15, 2023 · 03:15 PM

We also type the evidence shape (what goes in data-*) so it doesn't drift.

If evidence is a product surface, it's worth typing like any other surface.

Tomas Rivera
Nov 12, 2023 · 04:04 AM

Counterpoint: evidence typing can tempt people to render too much evidence.

We type the evidence we already want (lane, posture, identity), not every internal variable.

Salma Qureshi
Dec 02, 2023 · 02:02 AM

Everyday types are also a social tool: they reduce arguments in code review because everyone shares the same vocabulary.

Instead of "isLoading", you argue about which lane you're in.

Rowan Pierce
Dec 20, 2023 · 06:18 PM

If you want one habit: type your defaults and your lanes first. Everything else can be gradual.

Those two things pay back immediately in UI coherence.

Jules Kwon
Dec 31, 2023 · 09:09 AM

The handbook is boring in the best way. Boring types make boring bugs.

And boring bugs are the ones you can fix quickly.