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

161
Views
Proper way to declare json object (typescript)

I have the following json file with data:

[{
    "sectionKey": "key1",
    "sectionName": "name",
    "content": []
  },
  {
    "sectionKey": "key2",
    "sectionName": "name",
    "content": []
  }
]

My question is: how to declare the content of the array in typescript? like "Type"[]. Please do not suggest using any[] since it removes all type checking provided by TypeScript.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

interface CoolObject {
  sectionKey: string;
  sectionName: string;
  content: Array<any>;
}

const greatArray: CoolObject[] = [
  {
    sectionKey: 'key1',
    sectionName: 'name',
    content: [],
  },
  {
    sectionKey: 'key2',
    sectionName: 'name',
    content: [],
    foobar: 'something' // not assignable to type 'CoolObject'
  },
];

If it's the 'content' poperty you're trying to typehint you can use Array<YourType> or YourType[] too.

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!