How to specify generic object type in TypeScript?

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.