Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
How to declare string > string > number structure in TypeScript?

I need to declare a useState, but I do not clealy understand TypeScript. What should I write in place of XXXXXX. I have a strict JSON with string > string > number structure and I will populate selectedLayoutItemIds from it. Top level id is called eventTimeId, 2nd level I would call layoutItemId, 3rd level count. Would you help a bit?

const [selectedLayoutItemIds, setSelectedLayoutItemIds] = useState<
    { [eventTimeId: string]: XXXXXX } | undefined
  >(); 
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You only have to describe the structure of the data as you would do in a regular json and the 1st & 2nd level keys will be treated as strings:

interface LayoutItemIds { 
    eventTimeId: {
        layoutItemId: {
            count: number;
        }
    } 
}

const [selectedLayoutItemIds, setSelectedLayoutItemIds] = useState<LayoutItemIds | undefined>(); 

Here is a playground to see it in action.

about 4 years ago · Juan Pablo Isaza Report

0

Finally I declared a new interface:

export type LayoutItemIdsWithAvailability = {
  [layoutItemId: string]: number;
};

and used here:

const [selectedLayoutItemIds, setSelectedLayoutItemIds] = useState<
  { [eventTimeId: string]: LayoutItemIdsWithAvailability } | undefined
>();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!