3

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?

1
  • 2
    I think that Record<string, number> is what you need in this case. it just defines a Record with keys of type string and values of type number Commented Jul 4, 2021 at 16:40

2 Answers 2

5
interface MyObject { [key: string]: number };
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.