Six confusing compiler errors and what each one is really telling you. TypeScript is at its best when you barely notice it. The goal of this post is fewer annotations, not more, while catching the bugs that actually reach production.
Reading the compiler’s mind
Inference covers most local code. Annotate function parameters and public return types, and let the compiler fill in everything else. If you find yourself writing as, stop and ask which check is missing.
We have been running this approach for several months now. The initial setup took about a day, and the ongoing cost is close to zero once the team knows where to look.
What we would change next time
Questions, corrections, and war stories are welcome in the comments. Several of our best follow-up posts started as a reader pointing out something we had missed.
- Annotate parameters and exported return types.
- Validate external data once, at the edge.
- Prefer discriminated unions over optional flags.
- Treat every as cast as a code smell to review.
This finally clicked for me after reading the docs three times.
Tried it on a side project over the weekend and it worked first time, which never happens.
Is there a repo with the full example? Happy to open a PR with a TypeScript version.
Came for the snippet, stayed for the explanation.
Solid write-up. The warning about caching bit us hard last year.
Glad it helped!
How does this hold up on older Safari versions? That is where we always get burned.
Clear, practical, no fluff. More of this, please.