Edvins' Newsletter

Share this post

Exploring TypeScript: generics (w/ React example)

edvins.substack.com

Discover more from Edvins' Newsletter

A newsletter about front-end engineering.
Continue reading
Sign in

Exploring TypeScript: generics (w/ React example)

TypeScript generics is a topic I needed help grasping for a long time. I decided to learn about it and write a blog post to understand it better. As well as play around with real-world React example.

Edvins Antonovs
Sep 1, 2023
Share this post

Exploring TypeScript: generics (w/ React example)

edvins.substack.com
Share

Hey, it’s Edvins. Happy Friday! We made it through this week alive.

The last post about useMemo overdose went viral on /r/reactjs (~45.5k views), This Week In React newsletter (~25k developers), and even inspired @shashkovdanil to create an eslint-plugin-usememo-recommendations (~20 github stars already) eslint plugin. My digital garden gained a lot of traction and page views, and I got an extra ~15 newsletter subscribers. I call it a huge success, especially considering that while writing those blog posts, I have zero expectations that anyone will read them.

Let’s return to this week's post — Exploring TypeScript generics. It would be best if you didn’t waste any time, so I have already prepared the tl;dr edition for those who want to get to the topic. Yet to see its usage with the React `useFetch` hook, check out the link below.

tl;dr

  • TypeScript generics is a powerful tool that significantly enhances your code's flexibility and type safety.

  • You can create reusable components and functions that work seamlessly with different data types by leveraging generics.

  • The React custom useFetch hook example showcased how generics can help you handle diverse API responses while maintaining type correctness.

  • As your projects evolve, incorporating generics into your toolkit will prove invaluable.


Exploring TypeScript generics (w/ React example)

Share this post

Exploring TypeScript: generics (w/ React example)

edvins.substack.com
Share
Comments
Top
New

No posts

Ready for more?

© 2023 Edvins Antonovs
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing