jotaijs / jotai-tanstack-query

Jotai integration library for TanStack Query
MIT License
210 stars 14 forks source link

Unknown type after 0.8.2 update #67

Closed spacepolice10 closed 7 months ago

spacepolice10 commented 8 months ago

Hi there, thank you for the great job done over this library

I found out that after updating to any versions newer than 0.8.1, VSCode and build tools (webpack, turbopack) say that type of atomWithQuery is unknown. Typescript doesn't help to provide correct typings related to Tanstack Query Core for some reason and Jotai itself can't handle such atoms using get & set. I tried it on Next.js 14.1.0 with jotai-tanstack-query 0.8.3. Same thing happens on any atomWithQuery no matter what settings are passed to inner objects. Anything I can do about that. For now I just switched back to 0.8.1. and it runs fine. Thank you for any info in advance

EloToJaa commented 8 months ago

Hi, I have a similar problem as @spacepolice10 Repo

For example in file ./src/atoms/quiz.ts

export const quizNameAtom = atom<string>(
  get => get(quizAtom).data?.data.name ?? "Go Back"
);

export const quizLengthAtom = atom<number>(
  get => get(quizAtom).data?.data.questions.length ?? 0
);

export const quizAtom = atomWithQuery(get => ({
  queryKey: ["quiz", get(userNameAtom), get(quizSlugAtom)],
  queryFn: () =>
    api.get<QuizResponse>(
      `/api/v1/Quiz/${get(userNameAtom)}/${get(quizSlugAtom)}`
    ),
}));

I get this errors

src/atoms/quiz.ts:21:10 - error TS2571: Object is of type 'unknown'.

21   get => get(quizAtom).data?.data.name ?? "Go Back"
            ~~~~~~~~~~~~~

src/atoms/quiz.ts:25:10 - error TS2571: Object is of type 'unknown'.

25   get => get(quizAtom).data?.data.questions.length ?? 0
            ~~~~~~~~~~~~~

package.json

mfisher87 commented 8 months ago

Thank you so much for opening this issue, it saved me tons of time debugging :heart: :heart: :heart:

kalijonn commented 8 months ago

68 should fix this. There's still some inconsistency around types but this should bring it back to 0.8.1.

Let me know if its still broken.

EloToJaa commented 8 months ago

It works now. Thanks.