Hacker News new | ask | show | jobs
by dtagames 598 days ago
In my experience, very few projects are really TS "all the way down." Since all valid JS is also Typescript, what really happens is that you're writing JS with a sprinkling of TS where it is helpful and nowhere else.

A good place to start is by adding type declarations to a function, to specify the type of parameters it takes and the type of values it returns. This introduces the idea of type checking at compile time so you can spot errors in your calls to those functions or your use of their results when they don't match the type you specified. This is the only purpose of Typescript. It has no programming functions of any kind. That's all JS.

Once you've built and called a function with types on it (and VS Code is excellent for these experiments), the next thing to try is building an interface, that is a data shape of your own design. This is where the rocket takes off because instead of just saying your function needs "an object" parameter, you can specify the exact form of that object and the compiler will help you enforce that.

If you've mastered types in function calls and interfaces (and custom types, which are basically the same), congratulations because you know 90% of how TS is really used in the wild.