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

[Question]: How to fix flowgen test after flow update #9090

Closed
dominictobias opened this issue Oct 4, 2023 · 3 comments
Closed

[Question]: How to fix flowgen test after flow update #9090

dominictobias opened this issue Oct 4, 2023 · 3 comments
Labels

Comments

@dominictobias
Copy link

dominictobias commented Oct 4, 2023

What do you want to know?

I'm updating a couple of things in flowgen (since Flow now supports most of the missing utils)

After updating flow-bin to 0.217, this test started to fail:

it("should use spread when performing union of object types", () => {
  const ts = `
type Foo = { foo: number };
type Bar = { bar: string };
const combination: Foo & Bar;
`;
 // ...

The jest snapshot is now invalid:

exports[`should use spread when performing union of object types 1`] = `
"declare type Foo = {
  foo: number,
  ...
};
declare type Bar = {
  bar: string,
  ...
};
declare var combination: { ...Foo, ...Bar };
"
`;

Playground

I understand the principle that Bar has a spread and so could contain foo of the wrong type, but what is the correct way to do this in flow so I can fix the logic? Thanks

Edit: Looking at intersections/#toc-intersections-of-object-types it seems like the correct output should be declare var combination: Foo & Bar?

Edit edit: Assume that's correct, raised a PR: joarwilk/flowgen#201

@SamChou19815
Copy link
Contributor

I think the change is due to Flow changing the default of exact_by_default=true around 0.200.

declare var combination: Foo & Bar looks reasonable to me. Although you can also choose to interpreting all TS object types as exact, so that the spread can continue to work.

Does this answer your question?

@gkz
Copy link
Member

gkz commented Oct 6, 2023

There is a blog post about the exact by default change: https://medium.com/flow-type/exact-object-types-by-default-by-default-cc559af6f69

@dominictobias
Copy link
Author

Thanks for the info makes sense!

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

3 participants