-
Notifications
You must be signed in to change notification settings - Fork 180
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
refactor(js): Fix a variety of type definitions that will break in future Flow versions #4749
Conversation
Codecov Report
@@ Coverage Diff @@
## edge #4749 +/- ##
==========================================
+ Coverage 57.96% 58.18% +0.21%
==========================================
Files 956 956
Lines 26189 26467 +278
==========================================
+ Hits 15181 15400 +219
- Misses 11008 11067 +59
Continue to review full report at Codecov.
|
@@ -49,7 +50,7 @@ function ConfirmPositionContents(props: Props) { | |||
{...{ labware, calibrator, calibrateToBottom, useCenteredTroughs }} | |||
buttonText={confirmButtonText} | |||
/> | |||
<JogControls {...props} /> | |||
<JogControls jog={jog} /> |
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.
<JogControls>
only takes the one prop, so this code change is safe
<Icon | ||
name={'alert-circle'} | ||
className={styles.robot_item_icon} | ||
disabled |
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.
<Icon>
has no prop named disabled
const labwareType = robotSelectors.labwareType(props) | ||
const { onClick, ...labware } = props | ||
const { name, definition, slot } = labware | ||
const labwareType = robotSelectors.labwareType(labware) |
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.
This change was driven by switching Labware
to an exact object type. This minor code change keeps that all behaving
'debug', | ||
'silly', | ||
] | ||
type Logger = {| |
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.
This change demonstrates what I was talking about in my PR description. The app logger is simple enough that I figured I'd include this change as an example. plus, this will make the inevitable TS port a little easier
@@ -54,7 +54,6 @@ function LabwareList(props: Props) { | |||
modulesBySlot[lw.slot].name | |||
} | |||
isDisabled={disabled} | |||
confirmed={lw.confirmed} |
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.
lw
was already being spread in, so this line was unnecessary
@@ -68,8 +69,7 @@ export type DeckCalStartState = ApiCall<DeckStartRequest, DeckStartResponse> | |||
export type DeckCalCommandState = ApiCall<DeckCalRequest, DeckCalResponse> | |||
|
|||
type RobotCalState = { | |||
'calibration/deck/start'?: DeckCalStartState, | |||
'calibration/deck'?: DeckCalCommandState, | |||
[string]: any, |
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.
The typing on this state was an illusion and this file is super deprecated, so this just makes the danger more explicit. Unit tests are already in place for this state
|
||
export type RobotApiState = $Shape<{| | ||
...NetworkingState, | ||
[path: string]: any, |
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.
Same story here: types were an illusion
@@ -48,7 +48,6 @@ function mergeProps( | |||
|
|||
return { | |||
...passThruProps, | |||
...dispatchProps, |
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.
This just spread bare dispatch
into the props of the component, which was not used
0d519d2
to
4e05a81
Compare
@@ -168,7 +168,7 @@ const LabwareSelectionModal = (props: Props) => { | |||
>( | |||
defs, | |||
(acc, def: $Values<typeof defs>) => { | |||
const category = def.metadata.displayCategory | |||
const category: string = def.metadata.displayCategory |
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 wonder why it's not inferring this one?
EDIT: Oh it's string | LabwareDisplayCategory
and enum type isn't a valid key for object indexing in new flow 😠 ...what the heck, Flow?
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.
It's inferring string | LabwareCategory
where LabwareCategory
is a union type that makes Flow mad at its usage in a computed properly below this line
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.
Thanks for doing this! Looks good, only change I'd like is to protocol-designer/src/step-forms/selectors/index.js
which is just a slightly different workaround
overview
Flow v0.111 (latest: 0.115, ours: 0.110.1) introduced drastic changes to how object spreads are typed. If we upgrade, roughly 300 individual flow errors are introduced by ~150 lines in about ~50 files.
In my examination, we can break these cases down into a few categories:
changelog
This PR attempts to...
$FlowFixMe
s...without actually updating the version of Flow we use.
review requests
Point (4) above is a gnarly one. Basically, we do a lot of stuff like this:
Moving forward with Flow, this won't work anymore. (Aside: this also doesn't work with TypeScript, but TS has something else called Mapped Types which we would use instead)
This makes a whole host of things we do a lot stop working. Flow's recommendation moving forward to is explicitly define the types at the get-go...
...which works for some stuff, but is onerous for others.
Flow v0.115, however, is quite fast. So I think organizationally, we have some decisions to make regarding:
remaining flow errors
After this PR is applied, updating
flow-bin
and suppressing all errors results in:$FlowFixMe
s in...app/src/components/DeckMap/index.js
app/src/components/JogControls/index.js
app/src/components/RobotSettings/SelectNetwork/ConnectForm.js
app/src/components/calibrate-pipettes/Pipettes.js
app/src/pipettes/selectors.js
app/src/robot/reducer/calibration.js
components/src/deck/RobotCoordsForeignDiv.js
components/src/tooltips/Tooltip.js
protocol-designer/src/components/SettingsPage/FeatureFlagCard/FeatureFlagCard.js
protocol-designer/src/components/StepEditForm/fields/TipPosition/TipPositionModal.js
protocol-designer/src/components/modals/FilePipettesModal/index.js
protocol-designer/src/file-data/selectors/fileCreator.js
protocol-designer/src/labware-ingred/reducers/index.js
protocol-designer/src/labware-ingred/selectors.js
protocol-designer/src/load-file/migration/1_1_0.js
protocol-designer/src/persist.js
protocol-designer/src/step-forms/reducers/index.js
protocol-designer/src/step-forms/selectors/index.js
protocol-designer/src/step-generation/getNextRobotStateAndWarnings/dispenseUpdateLiquidState.js
protocol-designer/src/step-generation/test-with-flow/fixtures/robotStateFixtures.js
protocol-designer/src/step-generation/test-with-flow/mix.test.js
protocol-designer/src/step-generation/test-with-flow/transfer.test.js
protocol-designer/src/step-generation/utils/misc.js
protocol-designer/src/steplist/formLevel/generateNewForm.js
protocol-designer/src/steplist/formLevel/handleFormChange/dependentFieldsUpdateMix.js
protocol-designer/src/steplist/formLevel/handleFormChange/dependentFieldsUpdateMoveLiquid.js
protocol-designer/src/steplist/generateSubsteps.js
protocol-designer/src/steplist/substepTimeline.js
protocol-designer/src/tutorial/reducers.js
protocol-designer/src/ui/steps/actions/actions.js