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

Add tree-related types #1864

Merged
merged 31 commits into from
Nov 12, 2024
Merged

Add tree-related types #1864

merged 31 commits into from
Nov 12, 2024

Conversation

victorlin
Copy link
Member

@victorlin victorlin commented Oct 8, 2024

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

  • Check bundle size (ref)
  • Check type of ReduxNode.currentGt (ref)
  • Figure out what to do with strictNullChecks violations (ref)
  • Figure out how to sort the new types (ref)
  • Which files to put types in? (ref1, ref2)
  • De-duplicate RootState and TreeComponentStateProps? (ref)

Checklist

For later

@victorlin victorlin self-assigned this Oct 8, 2024
@nextstrain-bot nextstrain-bot temporarily deployed to auspice-victorlin-tree--ntadob October 8, 2024 18:54 Inactive
@victorlin victorlin temporarily deployed to auspice-victorlin-tree--ntadob October 8, 2024 20:49 Inactive
@victorlin victorlin temporarily deployed to auspice-victorlin-tree--ntadob October 8, 2024 22:47 Inactive
@jameshadfield
Copy link
Member

@genehack could you take a look at the types added / used here if you have a chance? 🙏

@victorlin victorlin temporarily deployed to auspice-victorlin-tree--ntadob October 9, 2024 17:56 Inactive
@victorlin victorlin mentioned this pull request Oct 21, 2024
4 tasks
@victorlin victorlin force-pushed the victorlin/tree-typing branch 2 times, most recently from e27d5d2 to 864ed12 Compare October 25, 2024 02:10
src/util/globals.js Outdated Show resolved Hide resolved
@victorlin
Copy link
Member Author

Progress update: I think I've renamed all the files that need to be renamed for sufficient types. I've temporarily turned off strictNullChecks to focus on the other typing issues and have addressed those. There are still several FIXMEs and any types that I'll come back to next week.

@victorlin victorlin force-pushed the victorlin/tree-typing branch 2 times, most recently from 0523c8f to 701d856 Compare October 30, 2024 00:51
@victorlin victorlin marked this pull request as ready for review October 30, 2024 00:52
Copy link
Member

@jameshadfield jameshadfield left a 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.

src/components/tree/phyloTree/layouts.js Show resolved Hide resolved
src/actions/tree.ts Outdated Show resolved Hide resolved
src/components/tree/phyloTree/types.ts Outdated Show resolved Hide resolved
src/components/tree/phyloTree/types.ts Outdated Show resolved Hide resolved
src/components/tree/phyloTree/types.ts Outdated Show resolved Hide resolved
src/components/tree/phyloTree/types.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@genehack genehack left a 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

src/actions/tree.ts Outdated Show resolved Hide resolved
src/components/tree/index.ts Outdated Show resolved Hide resolved
src/components/tree/phyloTree/change.ts Outdated Show resolved Hide resolved
src/components/tree/phyloTree/helpers.ts Outdated Show resolved Hide resolved
src/components/tree/phyloTree/phyloTree.ts Outdated Show resolved Hide resolved
src/components/tree/phyloTree/types.ts Outdated Show resolved Hide resolved
src/components/tree/phyloTree/types.ts Show resolved Hide resolved
src/util/colorScale.ts Outdated Show resolved Hide resolved
src/util/treeCountingHelpers.ts Outdated Show resolved Hide resolved
src/util/treeCountingHelpers.ts Outdated Show resolved Hide resolved
Copy link
Member

@jameshadfield jameshadfield left a 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.

src/components/tree/phyloTree/types.ts Outdated Show resolved Hide resolved
src/components/tree/tree.tsx Outdated Show resolved Hide resolved
src/components/tree/phyloTree/types.ts Outdated Show resolved Hide resolved
src/components/tree/phyloTree/types.ts Outdated Show resolved Hide resolved
src/components/tree/tree.tsx Outdated Show resolved Hide resolved
src/util/treeJsonProcessing.ts Show resolved Hide resolved
src/components/tree/phyloTree/types.ts Outdated Show resolved Hide resolved
src/components/tree/phyloTree/types.ts Outdated Show resolved Hide resolved
src/util/colorScale.ts Outdated Show resolved Hide resolved
src/util/colorScale.ts Show resolved Hide resolved
victorlin added a commit that referenced this pull request Nov 5, 2024
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)
victorlin added a commit that referenced this pull request Nov 5, 2024
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)>
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>
@victorlin
Copy link
Member Author

I'm going to merge this. The types are largely in-progress with further follow-up to be done with #1888 and #1889, but we're at a good point now where this can be merged to allow new work to happen on top of these changes.

@victorlin victorlin merged commit 1cf70f8 into master Nov 12, 2024
25 checks passed
@victorlin victorlin deleted the victorlin/tree-typing branch November 12, 2024 21:57
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.

5 participants