diff --git a/packages/ra-core/src/dataProvider/useGetManyReference.spec.tsx b/packages/ra-core/src/dataProvider/useGetManyReference.spec.tsx index af9eb7cd0a5..c282200e37d 100644 --- a/packages/ra-core/src/dataProvider/useGetManyReference.spec.tsx +++ b/packages/ra-core/src/dataProvider/useGetManyReference.spec.tsx @@ -418,4 +418,31 @@ describe('useGetManyReference', () => { expect(abort).toHaveBeenCalled(); }); }); + + it('should discriminate result type', () => { + // this is a TypeScript verification. It should compile. + const _ComponentToTest = () => { + const { data, error, isPending } = useGetManyReference<{ + id: number; + title: string; + }>('posts', { + target: 'comments', + id: 1, + }); + if (isPending) { + return <>Loading; + } + if (error) { + return <>Error; + } + return ( + + ); + }; + expect(_ComponentToTest).toBeDefined(); + }); }); diff --git a/packages/ra-core/src/dataProvider/useGetManyReference.ts b/packages/ra-core/src/dataProvider/useGetManyReference.ts index 4556deeeb09..4a38f8a7444 100644 --- a/packages/ra-core/src/dataProvider/useGetManyReference.ts +++ b/packages/ra-core/src/dataProvider/useGetManyReference.ts @@ -180,7 +180,7 @@ export type UseGetManyReferenceHookOptions = }; export type UseGetManyReferenceHookValue = - Omit, 'queryKey' | 'queryFn'> & { + UseQueryResult & { total?: number; pageInfo?: { hasNextPage?: boolean;