Skip to content

[TECH DEBT] Follow up to remove unnecessary TS generics when TS language supports partial type param inference #1456

Open

Description

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 of FilterCategories. 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:

This also causes awkwardness when using the table-control hooks, particularly when calling useTableControlState, because the TItem 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 means TItem gets resolved to unknown. This is mostly fine for this case, but it would be good to be able to explicitly pass TItem 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    kind/cleanupCategorizes issue or PR as related to cleaning up code, process, or technical debt.needs-priorityIndicates an issue or PR lacks a `priority/foo` label and requires one.needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions