2

I have an object that looks like this

{
  "sdfsdkhdfs": 1,
  "jjgtusdf": 2
}

where the keys are randomly generated, and there's an unspecified number of them. I want to create a type for this object in Typescript. How should I do this?

gkeenley
  • 6,088
  • 8
  • 54
  • 129
  • 2
    I think that `Record` is what you need in this case. it just defines a Record with keys of type `string` and values of type `number` – Liad Jul 04 '21 at 16:40

2 Answers2

4
interface MyObject { [key: string]: number };
Mr. Robot
  • 1,334
  • 6
  • 27
  • 79
1

The best you can do here is Record<string, number>.

Vojtěch Strnad
  • 2,420
  • 2
  • 10
  • 15