-
Notifications
You must be signed in to change notification settings - Fork 167
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
update useGenericObjectState types #3274
update useGenericObjectState types #3274
Conversation
314ea60
to
6799579
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3274 +/- ##
==========================================
+ Coverage 84.87% 84.89% +0.01%
==========================================
Files 1307 1307
Lines 29188 29183 -5
Branches 7872 7872
==========================================
Hits 24774 24774
+ Misses 4414 4409 -5
... and 3 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
frontend/src/pages/projects/types.ts
Outdated
export type UpdateObjectAtPropAndValue<T> = (propKey: keyof T, propValue: ValueOf<T>) => void; | ||
export type UpdateObjectAtPropAndValue<T> = <K extends keyof T>( | ||
propKey: K, | ||
propValue: Partial<T>[K], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this break the sanctity of our type behind the object store?
I can send undefined
to a value required by the type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current types are already broken in that I can supply a value from any prop for any key.
This isn't a perfect solution but a step that's better IMO. Enforces correct type but is allowing undefined
.
I suppose we can always keep looking for the perfect solution...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went with another approach that required altering several components which utilize this type. I was not able to find a solution whereby only the UpdateObjectAtPropAndValue
could be updated and solve all use cases.
6799579
to
bea9b86
Compare
[APPROVALNOTIFIER] This PR is APPROVED Approval requirements bypassed by manually added approval. This pull-request has been approved by: jeff-phillips-18 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
https://issues.redhat.com/browse/RHOAIENG-9748
Description
Improves the typing of
useGenericObjectState
such that the value is properly typed depending on the supplied property key. As a result, any unmatched value will result in a typescript error.Extracted common types for model serving into a separate type definition to be used by common form components.
Additionally, updated
useGenericObjectState
to accept a function to coincide with the API ofuseState
. This function argument can be used when the computation of default data is expensive.How Has This Been Tested?
npm run test:type-check
Ran existing tests.
Test Impact
N/A
Request review criteria:
Self checklist (all need to be checked):
If you have UI changes:
After the PR is posted & before it merges:
main