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

331
Views
A mapped type may not declare properties or methods - TypeScript

I have an interface, which should have keys that are in specific enum key type, but when I declare the type it gives this error:

A mapped type may not declare properties or methods.

Here is the code:

enum myEnum {
  propOne = 'propOne',
  propTwo = 'propTwo'
}

export interface myInterface {
  [key in myEnum]: anotherInterface;
}

I tried to specify the type also like this, but it didn't work and gave me syntax error:

export interface myInterface {
  [key in keyof typeof myEnum]: anotherInterface;
}

I also tried to use a normal object instead of an enum, but it gave the same error.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need to use Mapped type, not interface:

export type MyInterface = {
  [key in myEnum]: AnotherInterface;
}

over 4 years ago · Santiago Trujillo 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!