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

168
Views
Function overloading with generic types in Flow

I have a component

<ButtonGroup
  value={value}
  options={[1, 2, 3, 4, 5, 6].map((x) => {
    return { label: x, value: x };
  })}
/>

I am using Flow for type checking and want to know, whether it is possible to have ButtonGroup component be generically typed in such a way that it will raise a Flow error if type of value is not the same as type of option.[0].value? This should work for any matching type, e.g number, array, etc. and only raise if type of value and option[at_some_index].value are different

What I currently have:


type Props<T> = {
  options: Array<{
    label: React$Node,
    value: T,
  }>,
  value: T,

};

This works fine for checking matching types but only for a particular type. E.g if I do

export const ButtonGroup = ({options, value}: Props<number>) => {do stuff}

It will work for number types as expected, but if I add union types to have the same behaviour for strings, arrays, like so Props<number | string | []> flow stops raising an error if types of values don't match.

Below also doesn't work:

export const ButtonGroup = <T>({options, value}: Props<T>) => {do stuff}

I know this can be done in Typescript and was just wondering whether this can be done in Flow?

Thank you!

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!