Skip to content

Commit

Permalink
fix: better return type of Data - when no options are used it returns…
Browse files Browse the repository at this point in the history
… the doc type
  • Loading branch information
hannojg committed Dec 10, 2021
1 parent 2932c7e commit 7163295
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/firestore/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ export type OnceDataOptions<
export type Data<
T = FirebaseFirestoreTypes.DocumentData,
IDField extends string | undefined = undefined,
RefField extends string | undefined = undefined
> = T &
(IDField extends string ? Record<IDField, string> : {}) &
(RefField extends string
? Record<RefField, FirebaseFirestoreTypes.DocumentReference<T>>
: {});
RefField extends string | undefined = undefined,
// This is the type used with IDField and RefField merged onto the type
ResultType = T &
(IDField extends string ? Record<IDField, string> : {}) &
(RefField extends string
? Record<RefField, FirebaseFirestoreTypes.DocumentReference<T>>
: {})
> = IDField extends undefined
? RefField extends undefined
? T
: ResultType
: ResultType;

export type CollectionHook<T = FirebaseFirestoreTypes.DocumentData> =
LoadingHook<FirebaseFirestoreTypes.QuerySnapshot<T>, Error>;
Expand Down

0 comments on commit 7163295

Please sign in to comment.