Search⌘ K
AI Features

Using some standard generic types

Explore how to use TypeScript's standard generic types such as Array, Promise, Readonly, Partial, and Record to create flexible and reusable types. Understand their syntax and practical applications to enhance your React app's type safety and maintainability.

Understanding the generic type syntax #

Generic type allows us to create a specific type by allowing us to pass types into it as parameters. The parameters are passed inside angle brackets. If there are multiple parameters, they are separated by a comma.

const myVar = GenericType<SpecificType1, SpecificType2, ...>

This will make more sense as we use some of the standard generic types below.

Array<ItemType> #

One of the easiest generic types to understand is Array. In fact, we have used this before when ...