Categories
TypeScript Answers

How to add generic object types in TypeScript?

Spread the love

Sometimes, we want to add generic object types in TypeScript.

In this article, we’ll look at how to add generic object types in TypeScript.

How to add generic object types in TypeScript?

To add generic object types in TypeScript, we can use the Record type.

For instance, we write

const myObj: Record<string, any> = {
  //...
};

to set myObj to the Record with the key type set to string and the property value type is set to any.

Conclusion

To add generic object types in TypeScript, we can use the Record type.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *