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.