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

215
Views
Interface accepting any number of key value objects

I have the following interface / type as shown below:

export interface Bar {
  title?: string;
  [key: string]: string;
}

export type Foo = {
  name: string;
} & {
  [key: string]: Bar;
};

And when I try to declare a variable like so:

const someObject: Foo = {
  name: 'John',
  city: {
    a: 'something',
  },
};

It gives me the error:

Type '{ name: string; city: { a: string; }; }' is not assignable to type 'Foo '. Type '{ name: string; city: { a: string; }; }' is not assignable to type '{ [key: string]: Bar ; }'. Property 'title' is incompatible with index signature. Type 'string' is not assignable to type 'Bar'.


Question:

How to create an interface to satisfy an object like:

const someObject: Foo = {
  name: 'John',
  randomProperty1: { a: 'a' },
  randomProperty2: { b: 'b' },
  // any number of 'Bar'
};
about 4 years ago · Juan Pablo Isaza
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!