Skip to content

Conversation

rpl
Copy link
Member

@rpl rpl commented Oct 19, 2020

This PR contains a number of changes needed to pass the flowtype checks on flow >= v0.132.0 (see #2003).

Most of the changes are only applied to the flow type signatures, but for some of the flowtype errors I opted to make some small changes on the implementation side (when it did look more appropriate).

Many of the new flowtype checks errors in #2003 are related to the dependencies, it looks that more recent flow versions are detecting when the types used are coming from a dependency that isn't typed using flow and the resulting types are all going to degrate to any.

Unfortunately the npm modules that are triggering these flowtype errors do not have their own flowtype declarations, and there isn't a third party one in the flow-types repository neither.

The easiest approach seems to be to include our own flow-typed declarations files in the project repository.

These declaration files are only including the subset of the modules that is actually being used in the web-ext sources, everything else is currently omitted.

@coveralls
Copy link

coveralls commented Oct 19, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling ef7271a on rpl:fix/flow-type-signature-flow-ge-0.132.0 into 6819d66 on mozilla:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 99.936% when pulling f23cc7b on rpl:fix/flow-type-signature-flow-ge-0.132.0 into 9737acb on mozilla:master.

@rpl rpl requested a review from Rob--W October 19, 2020 13:59
Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

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

Does this mean that we have to maintain these type definitions whenever the library updates?
Would Flow complain if the external libraries' actual types change without us updating these types?

What's the benefit of adding these types over typing as any?

package.json Outdated
"src/**",
"index.mjs"
"index.mjs",
"flow-typed/*.js"
Copy link
Member

Choose a reason for hiding this comment

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

Why is this exported?

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed with @Rob--W to don't export the custom flow definitions for the third party dependencies used internally for now, we can include them if any other package depends from web-ext and would need them.

);

if (!this.wss) {
throw new Error('WebSocketServer closed');
Copy link
Member

Choose a reason for hiding this comment

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

What's this doing here? There will be a runtime error at this.wss.address() below, anyway.

Removing this would reduce the need for extra test coverage. (but since you have test coverage anyway, perhaps tweak the error message if you care about the scenario)

Copy link
Member Author

Choose a reason for hiding this comment

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

I opted to replace this with a $FlowIgnore suppress comment.

export class FirefoxAndroidExtensionRunner {
// Wait 3s before the next unix socket discovery loop.
static unixSocketDiscoveryRetryInterval = 3 * 1000;
static unixSocketDiscoveryRetryInterval: number = 3 * 1000;
Copy link
Member

Choose a reason for hiding this comment

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

Is Flow really that dumb to not be able to infer the type from this declaration?

Copy link
Member Author

Choose a reason for hiding this comment

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

as discussed in the triage meeting: I didn't dig too much, but I got the feeling that flow did enforce explicitly type annotations (instead of just trust what type did flow infer) on what it is being exported explicitly from a module (which to me does make kind of sense: "infer the type used internally as much as possible, enforce explicit type annotation of what is exported outside of a module").

});

const connectClient = async () => {
if (!runnerInstance.wss) {
Copy link
Member

Choose a reason for hiding this comment

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

Similarly there is going to be a runtime error anyway at runnerInstance.wss.address(). Does this help with anything?

Copy link
Member Author

Choose a reason for hiding this comment

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

I opted to replace this with a $FlowIgnore suppress comment.

@rpl rpl force-pushed the fix/flow-type-signature-flow-ge-0.132.0 branch from 3d7e21b to ef7271a Compare November 4, 2020 19:07
@rpl rpl merged commit 528f8a0 into mozilla:master Nov 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants