app-runtime
app-runtime copied to clipboard
fix(types): improve useDataQuery types
Key features
- Add types for the QueryResult based on the Query. So the
query-keys are typed on thedataobject when not passing in a generic type touseDataQuery. - Changes
QueryResultto beanyinstead ofJsonMap, due to problems withJsonMap. Please refer to this comment for more context. - Adds improved type to
engine.query, so it follows the same types asuseDataQuery. - Added an alias for the return type of
useDataQuery, because when I first worked with this I was very confused by theQueryRenderInput-name of the result ofuseDataQuery. - Adds
Pagertype and some related utility types to make it easy to create aResult-type that is paged.
Description
Builds on @eirikhaugstulen improvement of adding a generic type for useDataQuery.
Checklist
- [x] Have written Documentation
- If not needed, explain why, otherwise remove this bullet point
- [ ] Has tests coverage
- Only types are changed, so no runtime changes. But I did change some tests to be typed, so it's easier to check that the types work as they should
Screenshots
Type-completion on query-keys when not passing in a generic type
Could you add some docs with examples? Although possible, it's takes some time to wrap your head around what a type argument would/should look like.
Hello @Birkbjo
I have improvement suggestions if you're still working on this pull request. I think the generic type passed on the useDataQuery hook can be passed down to its refetch function so that its return value can also be typed.
Quality Gate failed
Failed conditions
1 New issue
1 New Code Smells (required ≤ 0)
See analysis details on SonarQube Cloud
Catch issues before they fail your Quality Gate with our IDE extension
SonarQube for IDE