Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

332
Vistas
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 Respuestas
Responde la pregunta

0

You need to use Mapped type, not interface:

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

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda