You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
exportfunctionuseDocument<// explicit generic as unknown to allow arbitrary types like numbers or stringsRextendsDocumentReference<unknown>>(documentRef: MaybeRefOrGetter<_Nullable<R>>,options?: UseDocumentOptions<_InferReferenceType<R>>): _RefFirestore<_InferReferenceType<R>|undefined>// this one can't be null or should be specified in the converter/** * Creates a reactive collection (usually an array) of documents from a collection ref or a query from Firestore. * Accepts a generic to **enforce the type** of the returned Ref. Note you can (and probably should) use * `.withConverter()` to have stricter type safe version of a collection reference. * * @param collectionRef - query or collection * @param options - optional options */exportfunctionuseDocument<T>(documentRef: MaybeRefOrGetter<_Nullable<DocumentReference>>,options?: UseDocumentOptions<T>): _RefFirestore<VueFirestoreDocumentData<T>|undefined>exportfunctionuseDocument<T>(documentRef: MaybeRefOrGetter<_Nullable<DocumentReference<unknown>>>,options?: UseDocumentOptions<T>): _RefFirestore<VueFirestoreDocumentData<T>|undefined>{// no unwrapRef to have a simpler typereturn_useFirestoreRef(documentRef,options)as_RefFirestore<VueFirestoreDocumentData<T>>}
The return type of useDocument should be _RefFirestore<VueFirestoreDocumentData<T> | null | undefined> but not _RefFirestore<VueFirestoreDocumentData<T> | undefined>, since it return a null reference if document does not exist.
This code, doc.value !== null, should be valid and have no warning.
Actual behavior
IDE warn at doc.value !== null
Additional information
No response
The text was updated successfully, but these errors were encountered:
FYI VueFirestoreDocumentData already includes null. This is likely related to your converter not being correctly typed. If it can return null, it should be a possibility in withConverter<T>. If typed correctly, it works:
BTW, your codesandbox is read only, when opening issues make sure to share writable playgrounds
Reproduction
codeSandbox
Steps to reproduce the bug
No step required.
count: null
is displayed on startup.Expected behavior
In https://github.com/vuejs/vuefire/blob/main/src/firestore/index.ts#L75-L104
The return type of useDocument should be
_RefFirestore<VueFirestoreDocumentData<T> | null | undefined>
but not_RefFirestore<VueFirestoreDocumentData<T> | undefined>
, since it return a null reference if document does not exist.This code,
doc.value !== null
, should be valid and have no warning.Actual behavior
IDE warn at
doc.value !== null
Additional information
No response
The text was updated successfully, but these errors were encountered: