Flow: Can't refine tuple union

Created on 4 Sep 2016  路  2Comments  路  Source: facebook/flow

First of all I apologize if the issue title is misleading, I don't know how else to put it.

The following is a minimal case of what I'd expect to work. Surprisingly (at least for me), it doesn't type check.

Tested with Flow 0.32

/* @flow */

type Foo = [string, string];
type Bar = [string, number];

type FooBar = Foo | Bar;


const x: FooBar = ["a", 2];
const y: Bar = x;

even adding type casting or explicit checks to typeof x[1] doesn't make the code type check

unionintersections

Most helpful comment

Here is a more extensive demo, showing that it doesn't work if the to-be-refined type is

  1. an array, it only seems to work with objects (Redux specific? 馃槣 )
  2. refined based on a typeof check, it only goes as far as refining when a literal is matched

https://flowtype.org/try/#0PQKgBAAgZgNg9gdzCYAoVxhgOpwE4DWAzgDRhwBGAVgKYDGALmAgJYMAWYRDeLAdgHMwMNjTwBDGGAZwwfcXjyIwAE0R8wdcURqoGATwAONMADE4cAExgAvGADeYAF5i4ALjAByKBc9k4fDQefACuALYUYmAAvgDcekYmAEIK1naOLkoenhQKfuSBHty8gjHxCcZmFil4aVVWYAA+YDWW5XQB3NLiBDRE5nCttmAAFAAeHgOtAJS2AHwOqGBgLFCjYwB0mbI2u14+cJ6z9kvLmp1M+pMWdWPxy9GojxhYACJwfXJwTAj4BP7Ueg-NicAyVGRyBRKJBqBAaLQ6ComAYAZmGGVcRR4-AE-kKcnCkTwZSRLQUaPSzkxBIiYjxQS42NKcXQYOR1XJw1RTTJeBR7Qu3V6-Q5fOG42ug3JsxsCxOy1WozZcDWm22tj2nmKOKOizO5z4XSu9QpYDup0ez0wYHenz432YfzIUPE+mYIMZJSEIgYYkk0lk8kUylh8O0ujZ9QALMMANreXxkUK0vAAXXikZqMbs8dyeHy2sE6dZiXqWa5FhjzSzAsNTAYPT6UwU2fWkqzMrlp0V41jAAZUxq7AnDsdTssOnWwMaBq3zQ8nqggA

All 2 comments

Here is a more extensive demo, showing that it doesn't work if the to-be-refined type is

  1. an array, it only seems to work with objects (Redux specific? 馃槣 )
  2. refined based on a typeof check, it only goes as far as refining when a literal is matched

https://flowtype.org/try/#0PQKgBAAgZgNg9gdzCYAoVxhgOpwE4DWAzgDRhwBGAVgKYDGALmAgJYMAWYRDeLAdgHMwMNjTwBDGGAZwwfcXjyIwAE0R8wdcURqoGATwAONMADE4cAExgAvGADeYAF5i4ALjAByKBc9k4fDQefACuALYUYmAAvgDcekYmAEIK1naOLkoenhQKfuSBHty8gjHxCcZmFil4aVVWYAA+YDWW5XQB3NLiBDRE5nCttmAAFAAeHgOtAJS2AHwOqGBgLFCjYwB0mbI2u14+cJ6z9kvLmp1M+pMWdWPxy9GojxhYACJwfXJwTAj4BP7Ueg-NicAyVGRyBRKJBqBAaLQ6ComAYAZmGGVcRR4-AE-kKcnCkTwZSRLQUaPSzkxBIiYjxQS42NKcXQYOR1XJw1RTTJeBR7Qu3V6-Q5fOG42ug3JsxsCxOy1WozZcDWm22tj2nmKOKOizO5z4XSu9QpYDup0ez0wYHenz432YfzIUPE+mYIMZJSEIgYYkk0lk8kUylh8O0ujZ9QALMMANreXxkUK0vAAXXikZqMbs8dyeHy2sE6dZiXqWa5FhjzSzAsNTAYPT6UwU2fWkqzMrlp0V41jAAZUxq7AnDsdTssOnWwMaBq3zQ8nqggA

related to #4556

Was this page helpful?
0 / 5 - 0 ratings