Categories
TypeScript Answers

How to specify generic object type in TypeScript?

Spread the love

Sometimes, we want to specify generic object type in TypeScript.

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

How to specify generic object type in TypeScript?

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

For instance, we write

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

to set myObj to the Record type with string keys and any type for the property values.

Conclusion

To specify generic object type 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 *