[TECH DEBT] Follow up to remove unnecessary TS generics when TS language supports partial type param inference #1456
Labels
kind/cleanup
Categorizes issue or PR as related to cleaning up code, process, or technical debt.
needs-priority
Indicates an issue or PR lacks a `priority/foo` label and requires one.
needs-triage
Indicates an issue or PR lacks a `triage/foo` label and requires one.
TypeScript generic type param lists are currently all-or-nothing. When passing type params to a function, you must either omit the list and allow all generics to be inferred or pass them all explicitly. This means if some of your types can be inferred from function arguments and some cannot, you need to explicitly repeat all the types including the infer-able ones. This is especially annoying when an inferred type is a long-winded string union such as is the case with the
key
properties in an array ofFilterCategories
. This occasionally makes for some quite redundant code, although TypeScript will still enforce that it is all consistent.There is a possible upcoming TypeScript language feature which would allow partial inference in type param lists and may alleviate this in the future. See TypeScript pull requests #26349 and #54047. If and when this feature is available in TypeScript, we should upgrade to that version and remove the unnecessary repetition in our code.
Some examples of where this repetition is present:
tackle2-ui/client/src/app/pages/controls/tags/tags.tsx
Line 170 in 82de730
tackle2-ui/client/src/app/pages/reports/components/identified-risks-table/identified-risks-table.tsx
Line 105 in 82de730
tackle2-ui/client/src/app/pages/controls/job-functions/job-functions.tsx
Line 62 in 82de730
tackle2-ui/client/src/app/pages/reports/components/adoption-candidate-table/adoption-candidate-table.tsx
Line 167 in 82de730
tackle2-ui/client/src/app/pages/applications/analysis-wizard/custom-rules.tsx
Line 119 in 82de730
tackle2-ui/client/src/app/pages/applications/manage-imports/manage-imports.tsx
Line 100 in 82de730
tackle2-ui/client/src/app/pages/controls/stakeholder-groups/stakeholder-groups.tsx
Line 124 in 82de730
tackle2-ui/client/src/app/pages/identities/identities.tsx
Line 110 in 82de730
tackle2-ui/client/src/app/pages/review/components/application-assessment-summary-table/application-assessment-summary-table.tsx
Line 84 in 82de730
tackle2-ui/client/src/app/pages/applications/components/application-tags/application-tags.tsx
Line 129 in 82de730
tackle2-ui/client/src/app/pages/applications/components/application-detail-drawer/application-facts.tsx
Line 34 in 82de730
tackle2-ui/client/src/app/pages/controls/business-services/business-services.tsx
Line 89 in 82de730
tackle2-ui/client/src/app/pages/applications/manage-imports-details/manage-imports-details.tsx
Line 101 in 82de730
This also causes awkwardness when using the table-control hooks, particularly when calling
useTableControlState
, because theTItem
type (the type of the actual API object items) cannot be inferred from arguments and the list of type params that would have to be passed to that hook is quite long. We made the decision to not pass any type params there, which meansTItem
gets resolved tounknown
. This is mostly fine for this case, but it would be good to be able to explicitly passTItem
without passing all the other types. See comments at https://github.com/konveyor/tackle2-ui/blob/main/client/src/app/hooks/table-controls/types.ts#L28-L32.The text was updated successfully, but these errors were encountered: