@@ -10,6 +10,7 @@ import type {
10
10
DocumentReference ,
11
11
Query ,
12
12
FirestoreError ,
13
+ DocumentData ,
13
14
} from 'firebase/firestore'
14
15
import {
15
16
getCurrentInstance ,
@@ -22,8 +23,6 @@ import {
22
23
import { isDocumentRef , _RefWithState } from '../shared'
23
24
import { firestoreUnbinds } from './optionsApi'
24
25
25
- export interface _RefFirestore < T > extends _RefWithState < T , FirestoreError > { }
26
-
27
26
export const ops : OperationsType = {
28
27
set : ( target , key , value ) => walkSet ( target , key , value ) ,
29
28
add : ( array , index , data ) => array . splice ( index , 0 , data ) ,
@@ -162,7 +161,7 @@ export function useCollection<
162
161
> (
163
162
collectionRef : R ,
164
163
options ?: UseCollectionOptions
165
- ) : Ref < _InferReferenceType < R > [ ] >
164
+ ) : _RefFirestore < _InferReferenceType < R > [ ] >
166
165
167
166
/**
168
167
* Creates a reactive collection (usually an array) of documents from a collection ref or a query from Firestore.
@@ -175,13 +174,15 @@ export function useCollection<
175
174
export function useCollection < T > (
176
175
collectionRef : CollectionReference | Query ,
177
176
options ?: UseCollectionOptions
178
- ) : Ref < T [ ] >
177
+ ) : _RefFirestore < VueFireQueryData < T > >
179
178
180
179
export function useCollection < T > (
181
180
collectionRef : CollectionReference < unknown > | Query < unknown > ,
182
181
options ?: UseCollectionOptions
183
- ) : Ref < _InferReferenceType < T > [ ] > | Ref < T [ ] > {
184
- return _useFirestoreRef ( collectionRef , options ) as _RefFirestore < T [ ] >
182
+ ) : _RefFirestore < VueFireQueryData < T > > {
183
+ return _useFirestoreRef ( collectionRef , options ) as _RefFirestore <
184
+ VueFireQueryData < T >
185
+ >
185
186
}
186
187
187
188
export interface UseDocumentOptions { }
@@ -198,7 +199,7 @@ export function useDocument<
198
199
> (
199
200
documentRef : R ,
200
201
options ?: UseDocumentOptions
201
- ) : _RefFirestore < _InferReferenceType < R > | null >
202
+ ) : _RefFirestore < _InferReferenceType < R > > // this one can't be null or should be specified in the converter
202
203
203
204
/**
204
205
* Creates a reactive collection (usually an array) of documents from a collection ref or a query from Firestore.
@@ -211,7 +212,7 @@ export function useDocument<
211
212
export function useDocument < T > (
212
213
documentRef : DocumentReference ,
213
214
options ?: UseDocumentOptions
214
- ) : _RefFirestore < T | null >
215
+ ) : _RefFirestore < VueFireDocumentData < T > >
215
216
216
217
export function useDocument < T > (
217
218
documentRef : DocumentReference < unknown > ,
@@ -248,3 +249,21 @@ export type _InferReferenceType<R> = R extends
248
249
| DocumentReference < infer T >
249
250
? T
250
251
: R
252
+
253
+ /**
254
+ * Type used by default by the `firestoreDefaultConverter`.
255
+ */
256
+ export type VueFireDocumentData < T = DocumentData > =
257
+ | null
258
+ | ( T & {
259
+ /**
260
+ * id of the document
261
+ */
262
+ readonly id : string
263
+ } )
264
+
265
+ export type VueFireQueryData < T = DocumentData > = Array <
266
+ Exclude < VueFireDocumentData < T > , null >
267
+ >
268
+
269
+ export interface _RefFirestore < T > extends _RefWithState < T , FirestoreError > { }
0 commit comments