Getting into TypeScript
2023-11-15Initial Reaction
I first heard about TypeScript many years ago. People seemed to praise it and made it seem as though it 'fixed' JavaScript. I took a quick peek at it and found a few things that withheld my interest.
- I felt that there was still way too much to learn about
JS. - I didn't understand the power of
TSand the value of type checking. - The syntax appeared chaotic and impossible to decipher.
So what if I could assign my types? Why was it worth bloating the code with this nonsense?
The Double Take
I eventually started to notice certain changes as I continued to
use JS. Documentation sites were starting to
provide TS snippets. Some of them even defaulted
to it. Sometimes certain questions I had were only available in TS.
I spent a good amount of time de-TS'ing various snippets. It was never
a fun time, but I learned more about the syntax during the process. I also
realized that VSCode started to autocomplete properties and methods as I typed.
This seemed like magic. How could it know what was attached to these things?
I learned that it was by the power of TS.
Maybe it was worth looking into again?
The Tipping Point
Some time had passed, and I found myself in a conversation where I was
showing someone how easy it is to build a site with create-react-app
via the React Docs. It's hard to describe how I felt
when I realized that you can't even find mention of the create-react-app
command! Instead, they recommend using someone else's framework. I did brief research
on the options and ended up using the first recommendation: Next.js.
This was just before the release of their app router. I took a chance on it and only learned
minimal information on the _pages router. Anyway, their documentation ONLY offered
snippets in TS. If Next.js truly was the future of web dev
and TS has that much of an impact on JS,
then I really needed to get on board.
Diving In
I really didn't enjoy using TS at first. There was quite
a bit to learn. I'm still only at the tip of the iceberg, but I'm definitely more
comfortable with it now.
I've recently re-written a few of my biggest projects into TS.
One of them remained client-only, and was also undergoing a transition from create-react-app
to Vite. Another one was an Express server
that was also undergoing the transition from CommonJS to ESM. A lot was happening at the time.
I learned a lot about TS in the process, and also grew to really enjoy it.
I also learned that my JS code was filled with many errors as far
as TS was concerned. I feel like a madman for testing my luck
with JS for so long.
It's nice to feel the power of TS and reap its rewards. It
may not be perfect, but it can only be an improvement from where I was.