Ask HN: Does TypeScript live up to the hype?
I’ve only ever used vanilla JavaScript ever since I got into WebDev and while it can annoying to work with at times, it’s really well rounded overall in my opinion especially the current version of ECMAScript. Combined with svelte it’s absolutely delightful.
Then I started hearing more about Typescript on Twitter and such and I got really curious because everyone had at least one good thing to say about it - mainly the data types aspect of it. Which is the only benefit that I can really wrap my head around.
24 comments
[ 3.3 ms ] story [ 17.1 ms ] threadThat's not my experience at all. I've found that you get most of the benefits via type inference with very little additional work. Although if you try to be super strict and forbid any use of "any" or casting, then that could get annoying and possibly counterproductive.
Why would you ever want to use any if you could avoid it? It completely undermines the benefits of TS. Most of the time you really want unknown or generics.
I have seen types and type unions get pretty complicated though
Then I saw a video of Rich Harris demonstrating the Svelte tools in VS code. The TS typing enabled autocomplete and even automatically importing files. That's what got me to try TypeScript. Perhaps TS could be faster than CoffeeScript, now.
(By now, ECMAScript has borrowed most of the good ideas from CoffeeScript, and other devs are more likely to be familiar with JS/TS vs CoffeeScript.)
Some times TS helps catch simple mistakes, but other times I feel like I am "fighting" with the TS type errors. Overall, I think it is worth using TS.
https://www.amazon.com/Programming-TypeScript-Making-JavaScr...
Typed languages such as C/C++ were annoying because the type system was too simple, but Typescript is much more powerful and it infers most things automatically. Plus you have structural types, so you can start converting one part of your project over at a time.
In general I don't see any reason to use Javascript without Typescript anymore, except if you are in an environment where you can't compile it for some reason.
It's really useful for providing good code hints and autocomplete, and for avoiding runtime crash bugs due to uncoerced types.
Give it a shot, a little at a time.
You can try this short guides with interactive exercises to learn about the type annotations. In 15 minutes you can get really familiar with it.
https://type-level-typescript.com/types-and-values
After that, Typescript documentation should fill any other gaps.
https://www.typescriptlang.org/docs/