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

104
Views
What is the correct way to pass through generics in this instance?

I am building a reusable table component and I have an optional render property that can take "any" type but I want to be specific and not use any

so I have this:

type Column<T> = {
  index: string
  render?: (arg?: T) => JSX.Element | string
}

type Columns = Column<T>[]

but the above line doesn't work as I'm not sure how to pass in the generic here?

then when I pass in the columns later like this:

const cols = [
  {
  index: "Phone Number",
  render: renderFunction('test'),
} as Column<string>

but how do I pass the generic to type Columns = Column<T>[] this line?

I can't pass it form Columns as it might be different for each Column

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use unknown there and use it like this:

type Columns = Column<unknown>[];

const columns: Columns = [{} as Column<string>, {} as Column<number>];
about 4 years ago · Juan Pablo Isaza Report
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!