Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript - Record<string, any> to Object

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.

like image 255
Lukas Bauer Avatar asked Oct 28 '25 12:10

Lukas Bauer


1 Answers

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.

like image 54
Alex Wayne Avatar answered Oct 30 '25 03:10

Alex Wayne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!