Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

333
Visualizações
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 Respostas
Responde à pergunta

0

You need to use Mapped type, not interface:

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

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda