How to learn the core typescript techniques

The core of TypeScript fits on an index card: annotate the boundary, describe shapes, narrow before you touch, and make a function generic only after the same pattern appears three times. The long tail of advanced types is real, but it is a tail. Drilling the core for a few weeks beats reading about the tail for a year.

Annotate the edges and let inference fill the middle

Every value that enters your code deserves a written type: a parameter, a response, a file read. Values computed inside a function rarely do, because the compiler already knows them and a second annotation is a second thing to keep correct.

Practice: take a function you wrote last week, delete every internal annotation, and keep only the signature. If it still compiles, those annotations were noise you were maintaining for free.

Narrowing is the workhorse

Narrowing is how you prove which shape you have before using it. typeof handles primitives, in handles object shapes, instanceof handles classes, and a shared tag field handles unions of objects. Most real TypeScript is this one skill repeated until it becomes reflex.

Practice: write a function over a three-case union, then delete one case and read the error. Restore it and make the compiler prove you handled everything.

Model states as unions, not as flags

A loading boolean plus an error string plus an optional result permits dozens of impossible combinations. A union of three shapes permits exactly three. The second is easier to read and much easier to narrow, because the tag does the deciding for you.

Practice: describe a form as idle, submitting, success, and error in one union, then write the rendering function without a single boolean check.

Read the type the compiler inferred

Hovering is a skill. Before fixing an error, ask what the compiler thinks the value is. The answer is often wider than expected: arrays widen, object literals widen, and callbacks without return types widen.

Practice: assign a value to a variable with a deliberately wrong annotation and read the message, because the message shows the inferred type you were guessing at.

Generics are a record of repetition

Write the same function three times with different types, notice what stays identical, then extract the generic version. Doing it in that order means you understand the abstraction. Doing it first means you copied one and cannot debug it.

Practice: turn a pair of nearly identical functions into one function with a single type parameter, and check that call sites still read clearly. If they need annotations to be legible, the abstraction is early.

Put these five drills on rotation, one a day, fifteen minutes each, on data you own. The advanced types will start to look like variations on the card rather than mysteries from somewhere else.