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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.