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

151
Views
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
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!