Skip to content

Commit 5c34b76

Browse files
committed
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.
1 parent 5736c7d commit 5c34b76

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

src/useFragment.tsx

+15-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@ export function useFragment<TKey extends KeyType>(
88
): $Call<KeyReturnType<TKey>>;
99
export function useFragment<TKey extends KeyType>(
1010
fragmentNode: GraphQLTaggedNode,
11-
fragmentRef: TKey | null,
11+
fragmentRef: TKey | null | undefined,
1212
): $Call<KeyReturnType<TKey>> | null;
1313
export function useFragment<TKey extends ArrayKeyType>(
1414
fragmentNode: GraphQLTaggedNode,
1515
fragmentRef: TKey,
1616
): ReadonlyArray<$Call<ArrayKeyReturnType<TKey>>>;
1717
export function useFragment<TKey extends ArrayKeyType>(
1818
fragmentNode: GraphQLTaggedNode,
19-
fragmentRef: TKey | null,
19+
fragmentRef: TKey | null | undefined,
20+
): ReadonlyArray<$Call<ArrayKeyReturnType<TKey>>>;
21+
export function useFragment<TKey extends ArrayKeyType>(
22+
fragmentNode: GraphQLTaggedNode,
23+
fragmentRef: TKey | null | undefined,
2024
): ReadonlyArray<$Call<ArrayKeyReturnType<TKey>>> {
2125
const [data] = useOssFragment(fragmentNode, fragmentRef, false, FRAGMENT_NAME);
2226
return data;
@@ -34,6 +38,10 @@ export function useSuspenseFragment<TKey extends ArrayKeyType>(
3438
fragmentNode: GraphQLTaggedNode,
3539
fragmentRef: TKey,
3640
): ReadonlyArray<$Call<ArrayKeyReturnType<TKey>>>;
41+
export function useSuspenseFragment<TKey extends ArrayKeyType>(
42+
fragmentNode: GraphQLTaggedNode,
43+
fragmentRef: TKey | null,
44+
): ReadonlyArray<$Call<ArrayKeyReturnType<TKey>>>;
3745
export function useSuspenseFragment<TKey extends ArrayKeyType>(
3846
fragmentNode: GraphQLTaggedNode,
3947
fragmentRef: TKey | null,
@@ -57,6 +65,11 @@ export function useFragmentSubscription<TKey extends ArrayKeyType>(
5765
fragmentRef: TKey,
5866
callback: (data: ReadonlyArray<$Call<ArrayKeyReturnType<TKey>>>) => void,
5967
): void;
68+
export function useFragmentSubscription<TKey extends ArrayKeyType>(
69+
fragmentNode: GraphQLTaggedNode,
70+
fragmentRef: TKey | null,
71+
callback: (data: ReadonlyArray<$Call<ArrayKeyReturnType<TKey>>>) => void,
72+
): void;
6073
export function useFragmentSubscription<TKey extends ArrayKeyType>(
6174
fragmentNode: GraphQLTaggedNode,
6275
fragmentRef: TKey | null,

src/usePagination.ts

+19-12
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,31 @@ import { useOssFragment } from './useOssFragment';
1111
export function usePagination<TQuery extends OperationType, TKey extends KeyType>(
1212
fragmentNode: GraphQLTaggedNode,
1313
fragmentRef: TKey,
14-
): // tslint:disable-next-line no-unnecessary-generics
15-
ReturnTypePagination<TQuery, TKey, KeyTypeData<TKey>>;
14+
): ReturnTypePagination<TQuery, TKey, KeyTypeData<TKey>>;
1615
export function usePagination<TQuery extends OperationType, TKey extends KeyType>(
1716
fragmentNode: GraphQLTaggedNode,
1817
fragmentRef: TKey | null,
19-
): // tslint:disable-next-line no-unnecessary-generics
20-
ReturnTypePagination<TQuery, TKey | null, KeyTypeData<TKey> | null> {
18+
): ReturnTypePagination<TQuery, TKey | null, KeyTypeData<TKey> | null>;
19+
export function usePagination<TQuery extends OperationType, TKey extends KeyType>(
20+
fragmentNode: GraphQLTaggedNode,
21+
fragmentRef: TKey | null,
22+
): ReturnTypePagination<TQuery, TKey | null, KeyTypeData<TKey> | null> {
2123
const [data] = useOssFragment(fragmentNode, fragmentRef, false, PAGINATION_NAME);
2224
return data;
2325
}
2426

2527
export function usePaginationFragment<TQuery extends OperationType, TKey extends KeyType>(
2628
fragmentNode: GraphQLTaggedNode,
2729
fragmentRef: TKey,
28-
): // tslint:disable-next-line no-unnecessary-generics
29-
ReturnTypePaginationSuspense<TQuery, TKey, KeyTypeData<TKey>>;
30+
): ReturnTypePaginationSuspense<TQuery, TKey, KeyTypeData<TKey>>;
31+
export function usePaginationFragment<TQuery extends OperationType, TKey extends KeyType>(
32+
fragmentNode: GraphQLTaggedNode,
33+
fragmentRef: TKey | null,
34+
): ReturnTypePaginationSuspense<TQuery, TKey | null, KeyTypeData<TKey> | null>;
3035
export function usePaginationFragment<TQuery extends OperationType, TKey extends KeyType>(
3136
fragmentNode: GraphQLTaggedNode,
3237
fragmentRef: TKey | null,
33-
): // tslint:disable-next-line no-unnecessary-generics
34-
ReturnTypePaginationSuspense<TQuery, TKey | null, KeyTypeData<TKey> | null> {
38+
): ReturnTypePaginationSuspense<TQuery, TKey | null, KeyTypeData<TKey> | null> {
3539
const [data] = useOssFragment(fragmentNode, fragmentRef, true, PAGINATION_NAME);
3640
return data;
3741
}
@@ -40,13 +44,16 @@ export function usePaginationSubscription<TQuery extends OperationType, TKey ext
4044
fragmentNode: GraphQLTaggedNode,
4145
fragmentRef: TKey,
4246
callback: (data: ReturnTypePagination<TQuery, TKey, KeyTypeData<TKey>>) => void,
43-
): // tslint:disable-next-line no-unnecessary-generics
44-
void;
47+
): void;
48+
export function usePaginationSubscription<TQuery extends OperationType, TKey extends KeyType>(
49+
fragmentNode: GraphQLTaggedNode,
50+
fragmentRef: TKey | null,
51+
callback: (data: ReturnTypePagination<TQuery, TKey | null, KeyTypeData<TKey> | null>) => void,
52+
): void;
4553
export function usePaginationSubscription<TQuery extends OperationType, TKey extends KeyType>(
4654
fragmentNode: GraphQLTaggedNode,
4755
fragmentRef: TKey | null,
4856
callback: (data: ReturnTypePagination<TQuery, TKey | null, KeyTypeData<TKey> | null>) => void,
49-
): // tslint:disable-next-line no-unnecessary-generics
50-
void {
57+
): void {
5158
useOssFragment(fragmentNode, fragmentRef, false, PAGINATION_NAME, callback);
5259
}

0 commit comments

Comments
 (0)