The Wayback Machine - https://web.archive.org/web/20211120135503/https://github.com/blitz-js/blitz/issues/2609
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

setQueryData seems to break resources typing #2609

Open
ugogo opened this issue Jul 28, 2021 · 4 comments
Open

setQueryData seems to break resources typing #2609

ugogo opened this issue Jul 28, 2021 · 4 comments

Comments

@ugogo
Copy link

@ugogo ugogo commented Jul 28, 2021

What is the problem?

When using useQuery, the resources' type seems to get lost when destructuring setQueryData

Paste all your error logs here:

Paste all relevant code snippets here:

What are detailed steps to reproduce this?

Inspect typing with and without setQueryData

Run blitz -v and paste the output here:

$ npx blitz -v
macOS Big Sur | darwin-x64 | Node: v16.3.0

blitz: 0.38.4 (local)

  Package manager: yarn
  System:
    OS: macOS 11.5
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 23.64 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.3.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.20.1 - /usr/local/bin/npm
    Watchman: Not Found
  npmPackages:
    @prisma/client: 2.26.0 => 2.26.0
    blitz: 0.38.4 => 0.38.4
    prisma: 2.26.0 => 2.26.0
    react: alpha => 18.0.0-alpha-ed6c091fe-20210701
    react-dom: alpha => 18.0.0-alpha-ed6c091fe-20210701
    typescript: ~4.3 => 4.3.5

Please include below any other applicable logs and screenshots that show your problem:

Here, plannings has the correct type

const [{ plannings }] = useQuery(getPlannings, {...})

CleanShot 2021-07-28 at 08 01 48@2x

But when using setQueryData, plannings has lost its typing

const [{ plannings }, { setQueryData }] = useQuery(getPlannings, {...})

CleanShot 2021-07-28 at 08 02 12@2x

@flybayer
Copy link
Collaborator

@flybayer flybayer commented Jul 29, 2021

Thanks! This is ready for someone to work on. Code is here: https://github.com/blitz-js/blitz/blob/canary/packages/core/src/use-query-hooks.ts#L35

@beerose
Copy link
Collaborator

@beerose beerose commented Jul 29, 2021

Hey @ugogo!

I tried reproducing it with Blitz examples and my side project, and I did see an any type in a tooltip a few times due to a VS Code lag. However, it was in various configurations — with and without destructuring setQueryData, or with destructuring some other field.
Did you notice this issue outside of your editor — e.g. with tsc not reporting an error that would happen if the value wasn't an any?

@ugogo
Copy link
Author

@ugogo ugogo commented Jul 30, 2021

hey @beerose
Just tried npx tsc with "noImplicitAny": true in my tsconfig.json and it's throwing an error when trying to map the resource
Like in this example
CleanShot 2021-07-30 at 08 37 58@2x

@arvinf07
Copy link

@arvinf07 arvinf07 commented Oct 2, 2021

I want to work on this issue!

@blitzjs-bot blitzjs-bot moved this from Ready to Work On to Assigned in Dashboard Oct 2, 2021
@beerose beerose mentioned this issue Nov 17, 2021
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment