From 5c34b76cbb6d046c571bf7e6938f224331dbfb16 Mon Sep 17 00:00:00 2001 From: Ian Obermiller Date: Fri, 20 Oct 2023 15:07:34 -0400 Subject: [PATCH 1/2] Emit declarations accepting null When you have an overloaded function the declaration doesn't emit type on the function body, so you you have to duplicate it. Practically speaking, usePagination does not allow `null` in TypeScript with the current release because that definition is not emitted. --- src/useFragment.tsx | 17 +++++++++++++++-- src/usePagination.ts | 31 +++++++++++++++++++------------ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/useFragment.tsx b/src/useFragment.tsx index ba23b648..c8223f2b 100644 --- a/src/useFragment.tsx +++ b/src/useFragment.tsx @@ -8,7 +8,7 @@ export function useFragment( ): $Call>; export function useFragment( fragmentNode: GraphQLTaggedNode, - fragmentRef: TKey | null, + fragmentRef: TKey | null | undefined, ): $Call> | null; export function useFragment( fragmentNode: GraphQLTaggedNode, @@ -16,7 +16,11 @@ export function useFragment( ): ReadonlyArray<$Call>>; export function useFragment( fragmentNode: GraphQLTaggedNode, - fragmentRef: TKey | null, + fragmentRef: TKey | null | undefined, +): ReadonlyArray<$Call>>; +export function useFragment( + fragmentNode: GraphQLTaggedNode, + fragmentRef: TKey | null | undefined, ): ReadonlyArray<$Call>> { const [data] = useOssFragment(fragmentNode, fragmentRef, false, FRAGMENT_NAME); return data; @@ -34,6 +38,10 @@ export function useSuspenseFragment( fragmentNode: GraphQLTaggedNode, fragmentRef: TKey, ): ReadonlyArray<$Call>>; +export function useSuspenseFragment( + fragmentNode: GraphQLTaggedNode, + fragmentRef: TKey | null, +): ReadonlyArray<$Call>>; export function useSuspenseFragment( fragmentNode: GraphQLTaggedNode, fragmentRef: TKey | null, @@ -57,6 +65,11 @@ export function useFragmentSubscription( fragmentRef: TKey, callback: (data: ReadonlyArray<$Call>>) => void, ): void; +export function useFragmentSubscription( + fragmentNode: GraphQLTaggedNode, + fragmentRef: TKey | null, + callback: (data: ReadonlyArray<$Call>>) => void, +): void; export function useFragmentSubscription( fragmentNode: GraphQLTaggedNode, fragmentRef: TKey | null, diff --git a/src/usePagination.ts b/src/usePagination.ts index 16f0d478..9fd68d04 100644 --- a/src/usePagination.ts +++ b/src/usePagination.ts @@ -11,13 +11,15 @@ import { useOssFragment } from './useOssFragment'; export function usePagination( fragmentNode: GraphQLTaggedNode, fragmentRef: TKey, -): // tslint:disable-next-line no-unnecessary-generics -ReturnTypePagination>; +): ReturnTypePagination>; export function usePagination( fragmentNode: GraphQLTaggedNode, fragmentRef: TKey | null, -): // tslint:disable-next-line no-unnecessary-generics -ReturnTypePagination | null> { +): ReturnTypePagination | null>; +export function usePagination( + fragmentNode: GraphQLTaggedNode, + fragmentRef: TKey | null, +): ReturnTypePagination | null> { const [data] = useOssFragment(fragmentNode, fragmentRef, false, PAGINATION_NAME); return data; } @@ -25,13 +27,15 @@ ReturnTypePagination | null> { export function usePaginationFragment( fragmentNode: GraphQLTaggedNode, fragmentRef: TKey, -): // tslint:disable-next-line no-unnecessary-generics -ReturnTypePaginationSuspense>; +): ReturnTypePaginationSuspense>; +export function usePaginationFragment( + fragmentNode: GraphQLTaggedNode, + fragmentRef: TKey | null, +): ReturnTypePaginationSuspense | null>; export function usePaginationFragment( fragmentNode: GraphQLTaggedNode, fragmentRef: TKey | null, -): // tslint:disable-next-line no-unnecessary-generics -ReturnTypePaginationSuspense | null> { +): ReturnTypePaginationSuspense | null> { const [data] = useOssFragment(fragmentNode, fragmentRef, true, PAGINATION_NAME); return data; } @@ -40,13 +44,16 @@ export function usePaginationSubscription>) => void, -): // tslint:disable-next-line no-unnecessary-generics -void; +): void; +export function usePaginationSubscription( + fragmentNode: GraphQLTaggedNode, + fragmentRef: TKey | null, + callback: (data: ReturnTypePagination | null>) => void, +): void; export function usePaginationSubscription( fragmentNode: GraphQLTaggedNode, fragmentRef: TKey | null, callback: (data: ReturnTypePagination | null>) => void, -): // tslint:disable-next-line no-unnecessary-generics -void { +): void { useOssFragment(fragmentNode, fragmentRef, false, PAGINATION_NAME, callback); } From c0b00abd6fc9d8bc07b65768cb805963b38ca898 Mon Sep 17 00:00:00 2001 From: Ian Obermiller Date: Fri, 20 Oct 2023 15:09:21 -0400 Subject: [PATCH 2/2] Also allow undefined --- src/usePagination.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/usePagination.ts b/src/usePagination.ts index 9fd68d04..cc418c7d 100644 --- a/src/usePagination.ts +++ b/src/usePagination.ts @@ -14,11 +14,11 @@ export function usePagination>; export function usePagination( fragmentNode: GraphQLTaggedNode, - fragmentRef: TKey | null, + fragmentRef: TKey | null | undefined, ): ReturnTypePagination | null>; export function usePagination( fragmentNode: GraphQLTaggedNode, - fragmentRef: TKey | null, + fragmentRef: TKey | null | undefined, ): ReturnTypePagination | null> { const [data] = useOssFragment(fragmentNode, fragmentRef, false, PAGINATION_NAME); return data;