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

152
Visualizações
How to pass an entire typecsript Enum as a component input on Angular?

I have a generic component that receives a Enum as input:

TableComponent<Columns> {

    @Input() columnsEnum: Columns;
}

The Enum looks like this:

export enum CardsEnum {
    CODE = 'sCode',
    NAME = 'sName',
    ID = 'sId'
}

And on my holder template, I have an instance of table-component as this:

<table-component [columnsEnum]="cardsEnum"></table-component>

And on my .ts of the holder component, I have a refererence to the Enum:

cardsEnum = CardsEnum

Angular infer the type of Columns properly, setting this to be CardsEnum. The problem is that on the template where I'm instantiating table-component, I receive the following error on the input:

Type 'typeof CardsEnum' is not assignable to type 'CardsEnum'.

And that's true, If I look to my holder component, the type that my variable stores is typeof CardsEnum, not CardsEnum:

(property) HolderComponent.cardsEnum: typeof CardsEnum

I can bypass the error setting cardsEnum = CardsEnum as unknown as CardsEnum but I don't want to do that.

I can't import the Enum directly on table-component because I'm going to pass different enums to this component, since its a generic component and that's my goal.

Any suggestions on how to fix this error?

about 4 years ago · Juan Pablo Isaza
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