Hacker News new | ask | show | jobs
by Benjamin_Dobell 1268 days ago
Depends whether you actually want to learn TypeScript or just how to consume it. More than 90% of TypeScript code I've seen is not actually taking advantage of TypeScript's static analysis capabilities to write safer more scalable code and is instead just being used as glorified autocomplete.

If you actually want to learn, then take a look at the implementation for stuff like Zod: https://github.com/colinhacks/zod/tree/master/src/helpers

You can do some really powerful stuff that hugely benefits your team. A decent example I stumbled across recently when I went to release my own library (that does the same thing) is https://github.com/leancodepl/ts-routes

3 comments

I wouldn’t discount the value of glorified autocomplete. Being able to hit the period (.) and see what’s inside this imported object is great, especially when consuming libraries as you mentioned.
So true, a lot of people I've worked with treat adding types as a box to check (eg afterthought) rather than something to leverage.
Your suggestion of zod is a very good one. I’ll take it further and suggest that if one wants to really embrace and learn TypeScript (or type systems like it), implementing your own zod-like library is an excellent learning experience. Building a set of composable “parse, don’t validate” primitives will help you think in the way the type system is designed to be most effective. And you’ll generally write better code for it.