Member-only story

Why You Should Use TypeScript’s <> Angle Brackets and Generic Types

I used to have no idea what <T> meant in the TypeScript docs, and I tried to avoid it, until I started combining React Query and React Hook Form. Here’s why I now love <> angle brackets.

Dr. Derek Austin 🥳
Totally TypeScript
Published in
15 min readAug 21, 2024

This is my face when I use <T> in TypeScript. Here’s why you should use <T>, too. Photo: Pauline Loroy Unsplash

TypeScript’s <> angle brackets used to strike fear into my heart on a daily basis, even though I thought I understood the concept of a “generic type.”

Now that I understand <> angle brackets have the power to slay the monster of any types in my code, I find them indispensable! 🥳

TypeScript’s <> angle brackets indicate generic TypeScript types, which allow you to create reusable “types within types” that wrap other types. They allow you to extend a type to work with any data type, without any.

Generics gives you a level of flexibility that is difficult to achieve without using them, especially if you (like me) love React Hooks and React Query.

This article will explain why I love TypeScript’s generics and why you should use them in your codebase, at least if you’re aiming for type safety.

We’re going to work through some practical examples, with an emphasis on insights from my own experience as a…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Totally TypeScript
Totally TypeScript

Published in Totally TypeScript

Can’t get enough TypeScript? Not sure what those <> angle brackets are for? We’ve got you covered.

Dr. Derek Austin 🥳
Dr. Derek Austin 🥳

Written by Dr. Derek Austin 🥳

Hi, I'm Doctor Derek! I've been a professional web developer since 2005, and I love writing about programming with JavaScript, TypeScript, React, Next.js & Git.

Responses (3)

Write a response