-
Notifications
You must be signed in to change notification settings - Fork 161
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
Add tree-related types #1864
Add tree-related types #1864
Conversation
34d10ba
to
38b94d4
Compare
38b94d4
to
4b25ff9
Compare
@genehack could you take a look at the types added / used here if you have a chance? 🙏 |
e27d5d2
to
864ed12
Compare
864ed12
to
0962aa8
Compare
Progress update: I think I've renamed all the files that need to be renamed for sufficient types. I've temporarily turned off |
0523c8f
to
701d856
Compare
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.
(Incomplete review - just posting now as I won't return to this until next week)
Looks good @victorlin - I'm only part way through the really big commit so far but will pick this up later. No action necessary at the moment I don't think.
I think I can review the correctness, but I haven't written enough TS to give advice about the big scale approach.
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.
picked some nits.
general feedback:
- if you're going to have a
types.ts
file, centralize all the types and interfaces on that level into that file (e.g., phylotree) - there are many methods where the arguments got typed, but the return value of the method did not -- i would urge you to try to always provide a type for the return value too
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 is a big undertaking - thanks for persevering Victor. It's already apparent how many bugs this has identified and will really help going forward. A few of my comments are blocking, but most are questions only.
51cb597
to
8bb453a
Compare
The conversion done in the previous commit came with hundreds of violations of this rule. While some could be addressed by better types, I think the types as-is are acceptable and we can live without these checks. 🚧 this is being re-evaluated: #1864 (comment)
4e51551
to
12aff24
Compare
The conversion done in the previous commits came with hundreds of violations of this rule. While this could be addressed by better types, it will take some work and can be deferred. A new issue/PR will be created after this is merged. <#1864 (comment)>
12aff24
to
9549dfb
Compare
The conversion done in the previous commits came with hundreds of violations of this rule. While this could be addressed by better types, it will take some work and can be deferred. A new issue/PR will be created after this is merged. <#1864 (comment)>
To satisfy the TypeScript rule noImplicitOverride.
To satisfy the ESLint rule @typescript-eslint/no-unused-vars.
Define the list of layouts in a single place.
Previous usage of parseInt was to convert float to integer. However, this isn't the intended usage of parseInt, which is made apparent with type checking - the parameter is expected to be a string type. Replace it with Math.trunc which is intended for converting float to integer.
Thse are typed to return a value that is not undefined.
This is easier for the TypeScript compiler to understand.
D3 expects the empty value to be null, not undefined.
Previously, there was no guarantee that an unknown error would produce a helpful message.
svgPropsToUpdate is Set<string>, not Set<string[]>.
Only KeyboardEvent has the shiftKey property.
calcTipRadii takes a key name of tipSelectedIdx. Previously, the value of idx was unused.
This should be a boolean, not whatever value newDistance is when defined.
This should be a boolean, not whatever value ReduxNode.parentInfo.original is when defined.
Not [string], [], [[string], [string]], or [string, [string]].
The extra value `true` had no effect.
These were initialized with default values but unused in the code.
Follow-up to "Lift node-selected modal to redux state" (f7e944d). This is left over from before we shifted the selected node to redux state.
This value was causing a type error because {} is not a Map. Remove it entirely since it isn't actually used - the value is created from scratch in src/middleware/performanceFlags.js.
There is a type error that prevents this from working properly: includes() takes a single string, but an array of PhyloNodes is given. It's not used on any existing calls to updateTipRadii, so just remove it entirely.
This previously worked because d3 was able to properly parse a color string out of RGBColor. However, it's better to keep things consistent and simple. Convert so that range is simply an array of hex color strings.
Centralize the defaults for consistency. Also, this avoids the need to mark the property as optional on the state.
This is more consistent with other booleans.
React will shallow merge the provided object into the existing state¹ which works for our usage. The type definition of setState does not allow partial state by default. Use 'never' to configure it to expect no fields in particular². ¹ <https://react.dev/reference/react/Component#setstate-parameters> ² <https://stackoverflow.com/a/55824499>
3e23f85
to
9c7644b
Compare
Description of proposed changes
Converted most but not all tree-related files in the commit with the same title as this PR. There were many type errors exposed by conversion. They have been addressed in the following commits.
I removed a few comments that are now self-explanatory with the added types. I also moved all JSDoc types and descriptions into the function signature.
Note that there are many optional properties in the newly defined interfaces. This is not ideal and doesn't capture the fact that many properties are conditional on things such as layout. But it's a starting point to be improved over time.
Notable threads
ReduxNode.currentGt
(ref)strictNullChecks
violations (ref)Checklist
If making user-facing changes, add a message in CHANGELOG.md summarizing the changes in this PR(to be done by a Nextstrain team member) Create preview PRs on downstream repositories.For later
strictNullChecks
violations #1888updateTipRadii
withtipSelectedIdx
#1891