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

177
Views
Flow does not recognize a refinement of disjoint union of tuples

Is there a way to refine a union of tuples correctly in flow? I see examples for object types in docs but looks like it has a difference for arrays and I don't see any clue for that case. I have this simple code:

/* @flow */

type A = ['a', string, string];
type B = ['b', number];

function process(param: A | B) {
  if (param[0] === 'a') {
    /*
     ERROR! Cannot get `param[2]` because `B` [1] only has 2 elements, 
     so index 2 is out of bounds. [invalid-tuple-index] 
    */
    console.log(param[2])
  } else {
    console.log(param[1])
  }
}

Flow Playground

But in typescript it distinguishes types correctly

type A = ['a', string, string];
type B = ['b', number];

function process(param: A | B) {
  if (param[0] === 'a') {
    console.log(param[2]) // Works! param: A
  } else {
    console.log(param[1]) // param: B
  }
}

Thanks!

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!