I have a Record<string, any> and would like to convert it to an object. I get this type unfortunately by Nock, so I can't change it though.
But to continue working with it, I need an object. Maybe someone knows the answer, because unfortunately I have not found anything myself.
The Record type is an object.
Record<string, any> is a type where the keys are string and every value is any. In fact you could write this type using object type notation.
type A = Record<string, any>
type B = { [key: string]: any }
// A and B are equivalent
And you can access it like an object:
const obj: Record<string, any> = { ... data here ... }
const aValue = obj.someProp
So if you have a Record<string, any>, you can access any string property like you would an object, and then you will get back an object typed as any. No transformation necesary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With