What I wish I knew before starting typescript

My first TypeScript file was a JavaScript file with the extension changed, and it compiled. That surprised me enough that I assumed the compiler was doing something clever in the background. It was not. Almost everything I got wrong in the first few months grew out of that single misunderstanding.

The types are gone by the time the code runs

TypeScript erases every annotation before your code reaches a browser or a server. What executes is JavaScript, with no checks and no safeguards at the moment of execution. That has two consequences worth internalising early, and they are not obvious when you are staring at a compile step.

First, a type is not validation. If a JSON response claims to be a user, the compiler believes you; only a runtime check can disagree. Second, debugging is still JavaScript debugging. If a value is undefined at the moment you need it, the answer lives in the data, not in the annotation you wrote.

The compiler is a collaborator, not a gatekeeper

I treated errors as a toll I had to pay before running the code. They are closer to a reviewer reading my work line by line: specific, patient, and only as useful as the types I hand over.

Short, named types produce short, readable errors. A forty-line message usually traces back to one enormous inferred type, and the fix is to simplify the type rather than to squint harder at the message.

The ecosystem moves faster than the language

Half the tutorials I followed used tools that had already been replaced. Library and tooling churn is normal; the language underneath changes slowly. Spend your attention on the parts that transfer between projects.

  • Stable: annotations, object shapes, unions, narrowing, generics.
  • Replaceable: bundlers, linters, test runners, project templates.

If a tutorial’s setup steps look unfamiliar, keep the concepts and find current setup instructions elsewhere. The ideas survive the tools.

You will read types far more than you write them

Most types in a real project arrive from libraries, not from your keyboard. Reading a signature — what goes in, what comes out, what might be null — is a skill, and it improves only with repetition.

A habit that helped me: hover every function you call for a week and say the signature out loud before using it. It feels painfully slow, and it builds the muscle that makes large codebases navigable.

What I would tell myself on day one

Write JavaScript you understand, add types where data enters and leaves, and let the compiler teach you the rest. Turn strict on from the start so the lessons arrive while the code is still small. Keep a file of questions, because your questions age better than the answers you were given.

None of this is knowledge you need before you begin. It is knowledge you will wish you had around week three, which is exactly when the compiler stops feeling like a nuisance and starts feeling like a second pair of eyes.