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

An error in useGetPosts in queries.ts #50

Open
GoDUsopp2005 opened this issue Mar 26, 2024 · 11 comments
Open

An error in useGetPosts in queries.ts #50

GoDUsopp2005 opened this issue Mar 26, 2024 · 11 comments

Comments

@GoDUsopp2005
Copy link

I am getting an error in queries.ts file as:

No overload matches this call.
Overload 1 of 3, '(options: UndefinedInitialDataInfiniteOptions<DocumentList | undefined, Error, InfiniteData<DocumentList | undefined, unknown>, QUERY_KEYS[], any>, queryClient?: QueryClient | undefined): UseInfiniteQueryResult<...>', gave the following error.
Argument of type '{ queryKey: QUERY_KEYS.GET_INFINITE_POSTS[]; queryFn: ({ pageParam }: { pageParam: number; }) => Promise<Models.DocumentList<Models.Document> | undefined>; getNextPageParam: (lastPage: any) => any; }' is not assignable to parameter of type 'UndefinedInitialDataInfiniteOptions<DocumentList | undefined, Error, InfiniteData<DocumentList | undefined, unknown>, QUERY_KEYS[], any>'.
Property 'initialPageParam' is missing in type '{ queryKey: QUERY_KEYS.GET_INFINITE_POSTS[]; queryFn: ({ pageParam }: { pageParam: number; }) => Promise<Models.DocumentList<Models.Document> | undefined>; getNextPageParam: (lastPage: any) => any; }' but required in type 'UseInfiniteQueryOptions<DocumentList | undefined, Error, InfiniteData<DocumentList | undefined, unknown>, DocumentList<...> | undefined, QUERY_KEYS[], any>'.
Overload 2 of 3, '(options: DefinedInitialDataInfiniteOptions<DocumentList | undefined, Error, InfiniteData<DocumentList | undefined, unknown>, QUERY_KEYS[], any>, queryClient?: QueryClient | undefined): DefinedUseInfiniteQueryResult<...>', gave the following error.
Argument of type '{ queryKey: QUERY_KEYS.GET_INFINITE_POSTS[]; queryFn: ({ pageParam }: { pageParam: number; }) => Promise<Models.DocumentList<Models.Document> | undefined>; getNextPageParam: (lastPage: any) => any; }' is not assignable to parameter of type 'DefinedInitialDataInfiniteOptions<DocumentList | undefined, Error, InfiniteData<DocumentList | undefined, unknown>, QUERY_KEYS[], any>'.
Property 'initialPageParam' is missing in type '{ queryKey: QUERY_KEYS.GET_INFINITE_POSTS[]; queryFn: ({ pageParam }: { pageParam: number; }) => Promise<Models.DocumentList<Models.Document> | undefined>; getNextPageParam: (lastPage: any) => any; }' but required in type 'UseInfiniteQueryOptions<DocumentList | undefined, Error, InfiniteData<DocumentList | undefined, unknown>, DocumentList<...> | undefined, QUERY_KEYS[], any>'.
Overload 3 of 3, '(options: UseInfiniteQueryOptions<DocumentList | undefined, Error, InfiniteData<DocumentList | undefined, unknown>, DocumentList<...> | undefined, QUERY_KEYS[], any>, queryClient?: QueryClient | undefined): UseInfiniteQueryResult<...>', gave the following error.
Argument of type '{ queryKey: QUERY_KEYS.GET_INFINITE_POSTS[]; queryFn: ({ pageParam }: { pageParam: number; }) => Promise<Models.DocumentList<Models.Document> | undefined>; getNextPageParam: (lastPage: any) => any; }' is not assignable to parameter of type 'UseInfiniteQueryOptions<DocumentList | undefined, Error, InfiniteData<DocumentList | undefined, unknown>, DocumentList<...> | undefined, QUERY_KEYS[], any>'.
Property 'initialPageParam' is missing in type '{ queryKey: QUERY_KEYS.GET_INFINITE_POSTS[]; queryFn: ({ pageParam }: { pageParam: number; }) => Promise<Models.DocumentList<Models.Document> | undefined>; getNextPageParam: (lastPage: any) => any; }' but required in type 'UseInfiniteQueryOptions<DocumentList | undefined, Error, InfiniteData<DocumentList | undefined, unknown>, DocumentList<...> | undefined, QUERY_KEYS[], any>'.ts(2769)
queryClient-aPcvMwE9.d.ts(324, 5): 'initialPageParam' is declared here.
queryClient-aPcvMwE9.d.ts(324, 5): 'initialPageParam' is declared here.
queryClient-aPcvMwE9.d.ts(324, 5): 'initialPageParam' is declared here.

Screenshot 2024-03-26 221335

@iam-annatar
Copy link

i have the same problem. did you resolve it?

@GoDUsopp2005
Copy link
Author

no not yet...

@Vidhanvyrs
Copy link

i did this try it if it's working or not

export const useGetPosts = () => {
  return useInfiniteQuery({
    queryKey: [QUERY_KEYS.GET_INFINITE_POSTS],
    queryFn: getInfinitePosts as any,
    getNextPageParam: (lastPage: any) => {
      if (lastPage && lastPage.documents.length === 0) {
        return null;
      }
      const lastId = lastPage.documents[lastPage?.documents.length - 1].$id;
      return lastId;
    },
    initialPageParam: null,
  });
};

@aedoardo1990
Copy link

thanks @Vidhanvyrs! I had the same issue and it works now

@iLakshya
Copy link

I am still receiving the same error even after changing the code. Please help

@aedoardo1990
Copy link

exactly the same error? I checked your const useGetPosts and as well the function getInfinitePosts in your code in github and they match my code

@iLakshya
Copy link

Yeah, exactly the same error

@iLakshya
Copy link

Can anyone help with this?

@anantiikenna
Copy link

anantiikenna commented Jul 8, 2024

I made some changes and it works. Try this it works for me.

export const useGetPosts = () => {
  return useInfiniteQuery({
    queryKey: [QUERY_KEYS.GET_INFINITE_POSTS],
    queryFn:getInfinitePosts,
    getNextPageParam: (lastPage) => {
      if (!lastPage || lastPage.documents.length === 0) return null;
      const lastDocument = lastPage.documents[lastPage.documents.length - 1];
      const lastId = lastDocument?.$id;

      if (!lastId) return null;

      // Convert lastId to a number if it is numeric, otherwise handle the error
      const numericLastId = parseInt(lastId, 10);
      if (isNaN(numericLastId)) return null;

      return numericLastId;
    },
    initialPageParam: 0, // Initialize with a number
  });
};
```  `

@iLakshya
Copy link

iLakshya commented Jul 8, 2024

Still the same error

@anantiikenna
Copy link

it can't give the same error, if it does check your getInfinitePost function in api.ts file change the type "any" to "string"
here is mine

export async function getInfinitePosts({ pageParam }: { pageParam: number }) {
  const queries: string[] = [Query.orderDesc("$updatedAt"), Query.limit(9)];

  if (pageParam) {
    queries.push(Query.cursorAfter(pageParam.toString()));
  }

  try {
    const posts = await databases.listDocuments(
      appwriteConfig.databaseId,
      appwriteConfig.postCollectionId,
      queries
    );

    if (!posts) throw Error;

    return posts;
  } catch (error) {
    console.log(error);
  }
}

still replace the useGetPosts function in query.ts file with the previous code I sent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants