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

Emit declarations for function overloads #255

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/useFragment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ export function useFragment<TKey extends KeyType>(
): $Call<KeyReturnType<TKey>>;
export function useFragment<TKey extends KeyType>(
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey | null,
fragmentRef: TKey | null | undefined,
): $Call<KeyReturnType<TKey>> | null;
export function useFragment<TKey extends ArrayKeyType>(
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey,
): ReadonlyArray<$Call<ArrayKeyReturnType<TKey>>>;
export function useFragment<TKey extends ArrayKeyType>(
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey | null,
fragmentRef: TKey | null | undefined,
): ReadonlyArray<$Call<ArrayKeyReturnType<TKey>>>;
export function useFragment<TKey extends ArrayKeyType>(
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey | null | undefined,
): ReadonlyArray<$Call<ArrayKeyReturnType<TKey>>> {
const [data] = useOssFragment(fragmentNode, fragmentRef, false, FRAGMENT_NAME);
return data;
Expand All @@ -34,6 +38,10 @@ export function useSuspenseFragment<TKey extends ArrayKeyType>(
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey,
): ReadonlyArray<$Call<ArrayKeyReturnType<TKey>>>;
export function useSuspenseFragment<TKey extends ArrayKeyType>(
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey | null,
): ReadonlyArray<$Call<ArrayKeyReturnType<TKey>>>;
export function useSuspenseFragment<TKey extends ArrayKeyType>(
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey | null,
Expand All @@ -57,6 +65,11 @@ export function useFragmentSubscription<TKey extends ArrayKeyType>(
fragmentRef: TKey,
callback: (data: ReadonlyArray<$Call<ArrayKeyReturnType<TKey>>>) => void,
): void;
export function useFragmentSubscription<TKey extends ArrayKeyType>(
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey | null,
callback: (data: ReadonlyArray<$Call<ArrayKeyReturnType<TKey>>>) => void,
): void;
export function useFragmentSubscription<TKey extends ArrayKeyType>(
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey | null,
Expand Down
33 changes: 20 additions & 13 deletions src/usePagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,31 @@ import { useOssFragment } from './useOssFragment';
export function usePagination<TQuery extends OperationType, TKey extends KeyType>(
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey,
): // tslint:disable-next-line no-unnecessary-generics
ReturnTypePagination<TQuery, TKey, KeyTypeData<TKey>>;
): ReturnTypePagination<TQuery, TKey, KeyTypeData<TKey>>;
export function usePagination<TQuery extends OperationType, TKey extends KeyType>(
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey | null,
): // tslint:disable-next-line no-unnecessary-generics
ReturnTypePagination<TQuery, TKey | null, KeyTypeData<TKey> | null> {
fragmentRef: TKey | null | undefined,
): ReturnTypePagination<TQuery, TKey | null, KeyTypeData<TKey> | null>;
export function usePagination<TQuery extends OperationType, TKey extends KeyType>(
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey | null | undefined,
): ReturnTypePagination<TQuery, TKey | null, KeyTypeData<TKey> | null> {
const [data] = useOssFragment(fragmentNode, fragmentRef, false, PAGINATION_NAME);
return data;
}

export function usePaginationFragment<TQuery extends OperationType, TKey extends KeyType>(
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey,
): // tslint:disable-next-line no-unnecessary-generics
ReturnTypePaginationSuspense<TQuery, TKey, KeyTypeData<TKey>>;
): ReturnTypePaginationSuspense<TQuery, TKey, KeyTypeData<TKey>>;
export function usePaginationFragment<TQuery extends OperationType, TKey extends KeyType>(
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey | null,
): ReturnTypePaginationSuspense<TQuery, TKey | null, KeyTypeData<TKey> | null>;
export function usePaginationFragment<TQuery extends OperationType, TKey extends KeyType>(
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey | null,
): // tslint:disable-next-line no-unnecessary-generics
ReturnTypePaginationSuspense<TQuery, TKey | null, KeyTypeData<TKey> | null> {
): ReturnTypePaginationSuspense<TQuery, TKey | null, KeyTypeData<TKey> | null> {
const [data] = useOssFragment(fragmentNode, fragmentRef, true, PAGINATION_NAME);
return data;
}
Expand All @@ -40,13 +44,16 @@ export function usePaginationSubscription<TQuery extends OperationType, TKey ext
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey,
callback: (data: ReturnTypePagination<TQuery, TKey, KeyTypeData<TKey>>) => void,
): // tslint:disable-next-line no-unnecessary-generics
void;
): void;
export function usePaginationSubscription<TQuery extends OperationType, TKey extends KeyType>(
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey | null,
callback: (data: ReturnTypePagination<TQuery, TKey | null, KeyTypeData<TKey> | null>) => void,
): void;
export function usePaginationSubscription<TQuery extends OperationType, TKey extends KeyType>(
fragmentNode: GraphQLTaggedNode,
fragmentRef: TKey | null,
callback: (data: ReturnTypePagination<TQuery, TKey | null, KeyTypeData<TKey> | null>) => void,
): // tslint:disable-next-line no-unnecessary-generics
void {
): void {
useOssFragment(fragmentNode, fragmentRef, false, PAGINATION_NAME, callback);
}