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

314
Views
Typescript: How do I define an interface for an object type's key value pair

I have an object called externalObject that has various key:value pairs.

I also have a typescript interface that is defined as the following:

interface TestObject{
   externalObject?: {}
}

My question is how do I further set the type for the externalObject's key as string and the values that are passed inside externalObject as string or number?

Note: we do not always know the key:value pairs. They vary each time.

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

0

You can set any number of key/types on an interface in a similar way to assigning an object. If you don't know the property names ahead of time, you can use a dynamic key:

export interface ITestObject {
  externalObject: {
    [key: string]: string | number;
  };
}

Alternatively, you can set the property as unknown and cast it to the proper type.

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!