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

Convert all object types to exact, or explicitly-inexact #3452

Closed
gnprice opened this issue Apr 11, 2019 · 6 comments · Fixed by #4518 or #4836
Closed

Convert all object types to exact, or explicitly-inexact #3452

gnprice opened this issue Apr 11, 2019 · 6 comments · Fixed by #4518 or #4836
Labels

Comments

@gnprice
Copy link
Member

gnprice commented Apr 11, 2019

(This becomes possible only with Flow v0.84, which we'll get as part of #3399; so it's blocked on that. And completely finishing it is blocked on later work in upstream Flow.)

Generally almost all our object types should be exact object types. See discussion in 61d2e34 and 7037393... and see the many examples in git log --grep exact of type errors that had been concealed by inexact object types and were discovered by making the object types exact.

The Flow team agrees, and they have been making changes to make it easier to work that way across a codebase:
https://medium.com/flow-type/on-the-roadmap-exact-objects-by-default-16b72933c5cf

We've already gone and made the bulk of our object types exact; see 61d2e34, 7037393, and 8370002 . With Flow v0.84, it becomes possible to explicitly mark as inexact the few types we actually want to describe that way. This task is to

  • do that;
  • for the remaining types that should be exact but aren't, make them exact (and fix whatever type errors stopped us from doing that before);
  • make sure we really have gotten every case of the previous two steps (with that flowlint promised in "Step 1" of the roadmap post linked above -- which doesn't seem to exist yet).
@gnprice gnprice added a-tools blocked on other work To come back to after another related PR, or some other task. labels Apr 11, 2019
gnprice added a commit that referenced this issue Apr 11, 2019
Similar to 7037393 a few months ago: done for the same reasons,
and in the exact same way.

The remaining cases that cause errors are mostly examples of #3451,
so we can convert them to exact object types as we fix that.

And then there are a handful of types that are genuinely meant to
be inexact object types.  When we upgrade soon to Flow v0.84 (as
part of #3399), we can make those explicit; tracking that as #3452.
@gnprice gnprice removed the blocked on other work To come back to after another related PR, or some other task. label Jul 25, 2019
@gnprice
Copy link
Member Author

gnprice commented Jul 25, 2019

#3399 is now done.

@gnprice
Copy link
Member Author

gnprice commented Feb 20, 2020

Flow upstream recently posted an update on how to do this upgrade:
https://medium.com/flow-type/how-to-upgrade-to-exact-by-default-object-type-syntax-7aa44b4d08ab

Looking through the steps there:

  1. Upgrading dev tools. Ensure all your tools support the new syntax.

We already have a few explicit inexact object types and haven't seen them break anything, so this is mostly set.

Checking the four package versions mentioned in the post, we're good on three of them, but we should

  • upgrade babel-eslint to at least v11-beta.
  1. Codemodding. Upgrade your codebase to use the new syntax.

The flowlint rule implicit-inexact-object, which would find places we have the old syntax, doesn't appear until Flow v0.101. We're on v0.92. So this will be easier to complete, and make it stay completed, once we're up to that Flow version.

Looks like RN v0.60 brings us Flow v0.98, and RN v0.61 brings Flow v0.105. So that Flow upgrade, in turn, will come with the RN v0.61 upgrade #3781.

OTOH that doesn't mean we need to wait to upgrade our code! There's a tool called flow-upgrade linked from that post, which will make the transformation automatically across our code. Might try that.

  1. Upgrading dependencies. Upgrade any code dependencies to use the new syntax.

Not going to worry about this until step 2 is done, or at least mostly done.

gnprice added a commit to gnprice/zulip-mobile that referenced this issue Feb 20, 2020
Does most of zulip#3452.

TODO:
 * Apply Prettier.
 * Actually read the diff, and review.
   It's likely that a lot of these should be *exact*.

Done with the following commands:

  $ yarn global add flow-upgrade
  $ flow-upgrade v0.83.0 v0.92.0
@chrisbobbe
Copy link
Contributor

  • upgrade babel-eslint to at least v11-beta.

I just tried babel-eslint at v11.0.0-beta.2, and it wants at least ESLint 6. We'll get that in, e.g., #4128.

Looks like RN v0.60 brings us Flow v0.98, and RN v0.61 brings Flow v0.105. So that Flow upgrade, in turn, will come with the RN v0.61 upgrade #3781.

Now done, in #4151, great!

@gnprice
Copy link
Member Author

gnprice commented Jul 13, 2020

Now that we're on RN v0.61 and Flow v0.105, we have that implicit-inexact-object flowlint rule available. So I made a quick experiment with it.

It finds 411 places. The majority of those are in the libdefs in flow-typed/npm/, which come from flow-typed upstream, so those are to be left for step 3. Something like 100-150 of them are in our code, though.

Skimming through, there's a mix. Some are indeed meant to be inexact. A lot of them -- I think probably the majority -- are meant to be exact, and we just haven't gotten around to making them say so. So we don't want to just sweep through and automatically add , ... to these types; we'll want to look at them one by one and mark them as exact or explicitly-inexact.

This flowlint sure makes easy to find places that need this conversion! So the steps to push this forward now look like:

  • Add implicit-inexact-object=warn to the [lints] section of .flowconfig.
  • Rerun Flow -- try npx flow --show-all-errors, as otherwise the warnings in flow-typed/ swamp it.
  • Look through the warnings, and add either | and | or , ... to each highlighted object type, as appropriate.
  • Skip any where it's not clear what's appropriate -- we can come back for those.

gnprice added a commit to wpj/zulip-mobile that referenced this issue Sep 16, 2020
The default for a Flow object type is to be "inexact", but most
types should actually be "exact".  (The Flow maintainers agree,
and have embarked on a migration to switch the default to exact;
see our zulip#3452.)  This one is typical in that respect.
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Mar 10, 2021
As noted in a recent commit where we upgraded to Flow v0.125, we
don't usually bump the Flow version outside of a React Native
upgrade commit.

But I found that we could get v0.126 without any added Flow errors
in React Native code -- which is even better than the situation with
Flow v0.125, where we saw one Flow error in one file.

Being on v0.126 is nice because we'll finally be able to drop our
comments like "this should really be exact -- see note in
jsonable.js" on many objects with indexer properties, and make those
object types exact.

- That, in turn, will help us address zulip#3452 more productively
  ("Convert all object types to exact, or explicitly-inexact").

- Fixing zulip#3452 is really a prerequisite for taking
  facebook/react-native@050a7dd01 (switching on `exact_by_default`),
  which is on the path to the RN v0.64 upgrade.

[1] https://flow.org/en/docs/config/options/#toc-exact-by-default-boolean
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Mar 10, 2021
As noted in a recent commit where we upgraded to Flow v0.125, we
don't usually bump the Flow version outside of a React Native
upgrade commit.

But I found that we could get v0.126 without any added Flow errors
in React Native code -- which is even better than the situation with
Flow v0.125, where we saw one Flow error in one file.

Being on v0.126 is nice because we'll finally be able to drop our
comments like "this should really be exact -- see note in
jsonable.js" on many objects with indexer properties, and make those
object types exact.

- That, in turn, will help us address zulip#3452 more productively
  ("Convert all object types to exact, or explicitly-inexact").

- Fixing zulip#3452 is really a prerequisite for taking
  facebook/react-native@050a7dd01 (switching on `exact_by_default`),
  which is on the path to the RN v0.64 upgrade.

[1] https://flow.org/en/docs/config/options/#toc-exact-by-default-boolean
@chrisbobbe
Copy link
Contributor

chrisbobbe commented Mar 10, 2021

(Oops, I accidentally caused this to be closed by saying “fix #3452” when I didn’t mean that #3452 was fully fixed. Reopening.)

@chrisbobbe chrisbobbe reopened this Mar 10, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Mar 11, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Mar 11, 2021
…on`.

The doc, at https://zulip.com/api/get-events, suggests that these
types already include all fields that will be present. So, make them
exact.

An instance of zulip#3452.
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Mar 11, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Mar 11, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Mar 11, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Mar 11, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Mar 11, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Mar 11, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Mar 11, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Mar 11, 2021
An instance of zulip#3452.

PR zulip#4465 is currently open for type-checking `MessageList`'s props.
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jun 30, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jun 30, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jun 30, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jun 30, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jun 30, 2021
I'm not so sure we need a libdef for `prettier`, actually.

Anyway, an instance of zulip#3452.
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jun 30, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jun 30, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jun 30, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jun 30, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jun 30, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jun 30, 2021
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 2, 2021
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 2, 2021
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 2, 2021
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 2, 2021
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 2, 2021
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 2, 2021
…iends.

In particular, more like `WebViewError, `WebViewMessage`, etc., just
above it.

An instance of zulip#3452.
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 2, 2021
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 2, 2021
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 2, 2021
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 2, 2021
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 2, 2021
I'm not so sure we need a libdef for `prettier`, actually.

Anyway, an instance of zulip#3452.
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 2, 2021
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 2, 2021
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 2, 2021
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 2, 2021
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 2, 2021
@gnprice gnprice closed this as completed in c96da70 Jul 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants