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

153
Vistas
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 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