@@ -13,54 +13,39 @@ export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>>
1313 : never ;
1414
1515// return non-nullable if `fragmentType` is non-nullable
16- export function useFragment < TType > (
17- _documentNode : DocumentTypeDecoration < TType , any > ,
18- fragmentType : FragmentType < DocumentTypeDecoration < TType , any > >
19- ) : TType ;
16+ export function useFragment < F extends DocumentTypeDecoration < any , any > > (
17+ _documentNode : F ,
18+ fragmentType : FragmentType < F >
19+ ) : ResultOf < F > ;
2020// return nullable if `fragmentType` is undefined
21- export function useFragment < TType > (
22- _documentNode : DocumentTypeDecoration < TType , any > ,
23- fragmentType : FragmentType < DocumentTypeDecoration < TType , any > > | undefined
24- ) : TType | undefined ;
21+ export function useFragment < F extends DocumentTypeDecoration < any , any > > (
22+ _documentNode : F ,
23+ fragmentType : FragmentType < F > | undefined
24+ ) : ResultOf < F > | undefined ;
2525// return nullable if `fragmentType` is nullable
26- export function useFragment < TType > (
27- _documentNode : DocumentTypeDecoration < TType , any > ,
28- fragmentType : FragmentType < DocumentTypeDecoration < TType , any > > | null
29- ) : TType | null ;
26+ export function useFragment < F extends DocumentTypeDecoration < any , any > > (
27+ _documentNode : F ,
28+ fragmentType : FragmentType < F > | null
29+ ) : ResultOf < F > | null ;
3030// return nullable if `fragmentType` is nullable or undefined
31- export function useFragment < TType > (
32- _documentNode : DocumentTypeDecoration < TType , any > ,
33- fragmentType : FragmentType < DocumentTypeDecoration < TType , any > > | null | undefined
34- ) : TType | null | undefined ;
31+ export function useFragment < F extends DocumentTypeDecoration < any , any > > (
32+ _documentNode : F ,
33+ fragmentType : FragmentType < F > | null | undefined
34+ ) : ResultOf < F > | null | undefined ;
3535// return array of non-nullable if `fragmentType` is array of non-nullable
36- export function useFragment < TType > (
37- _documentNode : DocumentTypeDecoration < TType , any > ,
38- fragmentType : Array < FragmentType < DocumentTypeDecoration < TType , any > > >
39- ) : Array < TType > ;
36+ export function useFragment < F extends DocumentTypeDecoration < any , any > > (
37+ _documentNode : F ,
38+ fragmentType : ReadonlyArray < FragmentType < F > >
39+ ) : ReadonlyArray < ResultOf < F > > ;
4040// return array of nullable if `fragmentType` is array of nullable
41- export function useFragment < TType > (
42- _documentNode : DocumentTypeDecoration < TType , any > ,
43- fragmentType : Array < FragmentType < DocumentTypeDecoration < TType , any > > > | null | undefined
44- ) : Array < TType > | null | undefined ;
45- // return readonly array of non-nullable if `fragmentType` is array of non-nullable
46- export function useFragment < TType > (
47- _documentNode : DocumentTypeDecoration < TType , any > ,
48- fragmentType : ReadonlyArray < FragmentType < DocumentTypeDecoration < TType , any > > >
49- ) : ReadonlyArray < TType > ;
50- // return readonly array of nullable if `fragmentType` is array of nullable
51- export function useFragment < TType > (
52- _documentNode : DocumentTypeDecoration < TType , any > ,
53- fragmentType : ReadonlyArray < FragmentType < DocumentTypeDecoration < TType , any > > > | null | undefined
54- ) : ReadonlyArray < TType > | null | undefined ;
55- export function useFragment < TType > (
56- _documentNode : DocumentTypeDecoration < TType , any > ,
57- fragmentType :
58- | FragmentType < DocumentTypeDecoration < TType , any > >
59- | Array < FragmentType < DocumentTypeDecoration < TType , any > > >
60- | ReadonlyArray < FragmentType < DocumentTypeDecoration < TType , any > > >
61- | null
62- | undefined
63- ) : TType | Array < TType > | ReadonlyArray < TType > | null | undefined {
41+ export function useFragment < F extends DocumentTypeDecoration < any , any > > (
42+ _documentNode : F ,
43+ fragmentType : ReadonlyArray < FragmentType < F > > | null | undefined
44+ ) : ReadonlyArray < ResultOf < F > > | null | undefined ;
45+ export function useFragment < F extends DocumentTypeDecoration < any , any > > (
46+ _documentNode : F ,
47+ fragmentType : FragmentType < F > | ReadonlyArray < FragmentType < F > > | null | undefined
48+ ) : ResultOf < F > | ReadonlyArray < ResultOf < F > > | null | undefined {
6449 return fragmentType as any ;
6550}
6651
@@ -84,5 +69,5 @@ export function isFragmentReady<TQuery, TFrag>(
8469 const fragName = fragDef ?. name ?. value ;
8570
8671 const fields = ( fragName && deferredFields [ fragName ] ) || [ ] ;
87- return fields . length > 0 && fields . every ( field => data && field in data ) ;
72+ return fields . length > 0 && fields . every ( ( field : keyof TFrag ) => data && field in data ) ;
8873}
0 commit comments