Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow Union Types do not work with RecordOf #1882

Open
Dagur opened this issue Oct 18, 2021 · 0 comments
Open

Flow Union Types do not work with RecordOf #1882

Dagur opened this issue Oct 18, 2021 · 0 comments
Labels

Comments

@Dagur
Copy link
Contributor

Dagur commented Oct 18, 2021

What happened

Cannot do any refinement to find out which type I'm working with and silence flow

How to reproduce

// @flow

import {
  type RecordOf,
} from "immutable";

type T1Props = {
  type: "t1",
  stuff: string
};
type T2Props = {
  type: "t2",
  stuff: string,
  moreStuff: string
};
type T1 = RecordOf<T1Props>;
type T2 = RecordOf<T2Props>;

function someFunc(test: T1 | T2) {
  if (test.type === "t2") {
    // Cannot get `test.moreStuff` because: Either property `moreStuff` is missing in  `RecordInstance` [1]. Or property `moreStuff` is missing in  `T1Props` [2]
    console.log(test.moreStuff);
  }

  // all branches are incompatible: Either property `moreStuff` is missing in  `RecordInstance` [1]. Or property `moreStuff` is missing in  `T1Props` [2].
  if (test.moreStuff) {
    console.log("We have t2");
  }
}

I was able to use a simple if to see if a property exists but now that I'm trying to upgrade to 4.0.0 I cannot find a way that works.

@jdeniau jdeniau added the flow label Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants