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 any fixes #1280

Merged
merged 10 commits into from Dec 10, 2019
Merged

Flow any fixes #1280

merged 10 commits into from Dec 10, 2019

Conversation

mwiencek
Copy link
Member

This PR mainly aims to reduce the number of uses of the any type. (There's only one remaining after this.) Where fixing the type implicated some smelly code, I fixed the code too.

This allows us to remove a use of `any`.

While we could also fix this by keeping OauthTypeT but checking that
it's equal to 'installed' or 'web' in handleOauthTypeChange, that sort
of check would be dead weight, and keeping OauthTypeT doesn't actually
provide any type safety here: by casting the string from the select to
`any` and then to OauthTypeT, we're trusting what we get from the
browser in any case.
Instead of putting all the button props into an object type, we can
inline them into the JSX element.
This was used to avoid an additional allocation per expand2 call, but
that's a premature optimization. Fixes some questionable uses of `any`
and removes some confusing code comments.
The main "fix" here is that LinkableEntity must be a disjoint union
distinguished by the entityType property.

The changes to MinimalCoreEntityT and MinimalAnnotatedEntityT (to make
them exact) were part of an alternate fix I was working on, and not
strictly necessary anymore, but I kept them because they're technically
correct.
This was used by EntityLink to determine whether there was a name
variation when `content` was a React element (rather than a string). It
tried to recurse into the React element tree and figure out the actual
text content of the element, sort of like `.textContent` would do in a
web browser. But this didn't work at all if the React element was a
custom component: by definition it's not rendered yet, so it's
impossible to know what the text content could be.

I also found only one actual case where this might be needed, and
simply changed that to set nameVariation directly. We still set
nameVariation automatically in cases where `content` is a string.

Removes a usage of the `any` Flow type.
This is deprecated:
https://reactjs.org/docs/react-dom.html#finddomnode

Fixes a use of the `any` Flow type in Tooltip.js.
Flow doesn't type the result of Object.entries in the way that we'd like
for exact object types yet. However, iterating over the keys works fine
and doesn't degrade readability at all.
Fixes a use of `any` in wrapGettext.js.

Note: flow-typed/npm/jed_v1.x.x.js is our own definition, not from
the flow-typed repository, so local modifications are fine. We use a
fork of Jed (on github at mwiencek/Jed), so perhaps it's better to move
the types there as a Flow declarations file.
Copy link
Member

@reosarevok reosarevok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be fine now :)

@mwiencek mwiencek merged commit 72a1f84 into metabrainz:master Dec 10, 2019
@mwiencek mwiencek deleted the flow-any-fixes branch December 10, 2019 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants