Description
openedon Oct 10, 2023
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.