Comment by golergka

3 years ago

It feels like the same information is repeated often 2, sometimes even 3 times. And overall, I don't think this book has anything more than what's already in official docs.

I would actually love a “Typescript: The good parts” as a spiritual sequel to Javascript: The good parts. [0] Something that starts at the basics and builds upon that knowledge layer by layer like this handbook, but doesn’t dedicate more than a page to any one topic, and doesn’t repeat itself. Not a tutorial, but more like a glossary ordered by abstraction.

Plus, there’s a lot of Typescript I would consider not part of the “good stuff”, we can leave out enums.

[0] https://www.goodreads.com/book/show/2998152-javascript

  • Try Dan Vanderkam's "Effective Typescript: 62 Specific Ways to Improve YourTypeScript" (O'Reilly). I'm no TS guru, but IMHO it's pretty well-grounded in first principles.

  • What's wrong with enums? Enum types in general are very useful.

    • If you mean traditional enums, called unions in Typescript and represented by the pipe symbol, then nothing. But if you mean the named Enum keyword in Typescript, then the problem is that they emit runtime code and aren't type safe.

    • Amongst their issues is the issue of enum vs const enum. These compile to different outputs and support different behaviors. It’s not possible to compile a TS file that uses them without looking at the enum declaration to see if it’s const. It’s no longer possible to strip the types and have something that any JS bundler can understand.

      1 reply →

    • Someone mentioned they shouldn't be in TS altogether in another thread

      shrugs

      I like em too

    • > What's wrong with enums?

      They don't compile down to just the same code with the type annotations and definitions removed, which is often considered to be the ideal that typescript should follow. Instead, they compile down to some more complicated blob of javascript. People critique and avoid typescript's namespaces for the same reason.

      > Enum types in general are very useful.

      You can use unions for the same purpose without the aforementioned drawback, and unions have other benefits which typescript's enums don't offer, like support for more complex data types, which makes unions closer to set of features more modern languages tend to offer via enums, while making enums closer to the barebones enums found in languages like C and C++ (effectively just a set of named constants enclosed into a type).

      1 reply →

yeah I took a look and couldnt help but feeling like it was a laundry list with minimal examples and not always telling you why or when you would use a certain feature of TypeScript. Example: TypeScript _does_ enable you to overload functions, but overloading functions is nearly never the best way to do something, often cited as a spaghetti code pattern