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
First flow types; port external links editor tests to Selenium #550
Conversation
85b379e
to
514d06e
Compare
.flowconfig
Outdated
.*/root/static/build/.* | ||
.*/t/.* | ||
|
||
[include] | ||
|
||
[libs] | ||
./node_modules/jsx-control-statements/jsx-control-statements.latest.flow.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using npm
3.10.10
, I have ./node_modules/jsx-control-statements/jsx-control-statements.flow.js
instead, resulting into the following message in flow
0.55.0
logs:
Skipping ./node_modules/jsx-control-statements/jsx-control-statements.latest.flow.js: No such file or directory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, guess I didn't git add
the package.json changes. It should be fixed now if you run npm install
again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'd also recommend doing npm install -g npm@latest
if you can though, the latest versions of npm
seem much less flaky/buggy for me.)
Point to the types supported by the latest version of flow.
Replaces PropTypes with flow types in the two modules that use those, adding types to the entire files as needed. It's currently a pain to type-check immutable-js records, so I removed those from the external links editor source in favor of plain objects.
This is causing tests to fail in the test container, though they pass fine locally.
This only seems to be necessary on our slow Jenkins server.
@@ -91,15 +108,15 @@ class ExternalLinksEditor extends React.Component { | |||
} | |||
|
|||
getOldLinksHash() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we check return type (similarly to parameters type)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point actually. Flow has type inference, so normally we don't have to specify types where it can figure them out on its own. But for external modules, it says this:
If a third-party library that has no type information is used by your project, Flow will treat it like any other untyped dependency and mark all of its exports as
any
. Interestingly, this is the only place that Flow will implicitly injectany
into your program.
Since we're returning the result of a lodash function, I believe the inferred return type is any
, which disables type checking wherever the function is used.
So adding return types is a good idea wherever we're calling an external library function and returning its result. A better idea, if possible, is pulling in types for the library via flow-typed
(mentioned in the link above), and letting flow infer the types from that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flow-typed only has types for lodash v4, so I'd prefer to do that in a later PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started to tickle updating to lodash v4 alredy.
This begins adding static type checking to our JavaScript with Flow: https://flow.org/
Only files beginning with a
// @flow
comment are checked, so this can be done incrementally.The types aren't yet checked during builds. I'll do that in a future PR, but for now devs are expected to run
flow
on their own.The types are stripped via a babel plugin.
This PR also ports the external links editor tests to Selenium, because I had trouble getting the finicky JS ones to pass consistently.