[Question]: How to fix flowgen test after flow update
sekoyo opened this issue · 3 comments
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 };
"
`;
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
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?
There is a blog post about the exact by default change: https://medium.com/flow-type/exact-object-types-by-default-by-default-cc559af6f69
Thanks for the info makes sense!