app-runtime icon indicating copy to clipboard operation
app-runtime copied to clipboard

fix(types): improve useDataQuery types

Open Birkbjo opened this issue 2 years ago • 3 comments

Key features

  1. Add types for the QueryResult based on the Query. So the query-keys are typed on the data object when not passing in a generic type to useDataQuery.
  2. Changes QueryResult to be any instead of JsonMap, due to problems with JsonMap. Please refer to this comment for more context.
  3. Adds improved type to engine.query, so it follows the same types as useDataQuery.
  4. Added an alias for the return type of useDataQuery, because when I first worked with this I was very confused by the QueryRenderInput-name of the result of useDataQuery.
  5. Adds Pager type and some related utility types to make it easy to create a Result-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

image Type-completion on query-keys when not passing in a generic type

Birkbjo avatar Apr 17 '23 23:04 Birkbjo

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.

Mohammer5 avatar Apr 24 '23 01:04 Mohammer5

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.

nnkogift avatar Sep 19 '23 10:09 nnkogift

Quality Gate Failed 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

sonarqubecloud[bot] avatar Nov 25 '24 12:11 sonarqubecloud[bot]