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

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

Open
mturley opened this issue Oct 10, 2023 · 1 comment
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.

Comments

@mturley
Copy link
Collaborator

mturley commented 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.

@mturley mturley added the tech-debt Technical debt label Oct 10, 2023
@mturley mturley changed the title Follow up to remove unnecessary TS generics when TS language supports partial type param inference [TECH DEBT] Follow up to remove unnecessary TS generics when TS language supports partial type param inference Oct 10, 2023
@sjd78 sjd78 added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. and removed tech-debt Technical debt labels Jul 18, 2024
@konveyor-ci-bot
Copy link

This issue is currently awaiting triage.
If contributors determine this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.
The triage/accepted label can be added by org members.

@konveyor-ci-bot konveyor-ci-bot bot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates an issue or PR lacks a `priority/foo` label and requires one. labels Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

2 participants