Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(useFirestore): fix falsy type error #2431

Merged
merged 1 commit into from Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/firebase/useFirestore/index.md
Expand Up @@ -30,8 +30,8 @@ const posts = useFirestore(postsQuery)
// you can use the boolean value to tell a query when it is ready to run
// when it gets falsy value, return the initial value
const userId = ref('')
const userQuery = computed(() => !!userId.value && doc(db, 'users', userId.value))
const userData = useFirestore(userQuery, [])
const userQuery = computed(() => userId.value && doc(db, 'users', userId.value))
const userData = useFirestore(userQuery, null)
```

## Share across instances
Expand Down
14 changes: 8 additions & 6 deletions packages/firebase/useFirestore/index.ts
Expand Up @@ -33,25 +33,27 @@ function isDocumentReference<T>(docRef: any): docRef is DocumentReference<T> {
return (docRef.path?.match(/\//g) || []).length % 2 !== 0
}

type Falsy = false | 0 | '' | null | undefined
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding Falsy fixed these errors

スクリーンショット 2022-11-12 0 53 30


export function useFirestore<T extends DocumentData>(
maybeDocRef: MaybeRef<DocumentReference<T> | false>,
maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>,
initialValue: T,
options?: UseFirestoreOptions
): Ref<T | null>
export function useFirestore<T extends DocumentData>(
maybeDocRef: MaybeRef<Query<T> | false>,
maybeDocRef: MaybeRef<Query<T> | Falsy>,
initialValue: T[],
options?: UseFirestoreOptions
): Ref<T[]>

// nullable initial values
export function useFirestore<T extends DocumentData>(
maybeDocRef: MaybeRef<DocumentReference<T> | false>,
initialValue?: T | undefined,
maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>,
initialValue?: T | undefined | null,
Copy link
Contributor Author

@kiyopikko kiyopikko Nov 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line fixed the error below

スクリーンショット 2022-11-12 0 53 50

options?: UseFirestoreOptions,
): Ref<T | undefined | null>
export function useFirestore<T extends DocumentData>(
maybeDocRef: MaybeRef<Query<T> | false>,
maybeDocRef: MaybeRef<Query<T> | Falsy>,
initialValue?: T[],
options?: UseFirestoreOptions
): Ref<T[] | undefined>
Expand All @@ -63,7 +65,7 @@ export function useFirestore<T extends DocumentData>(
* @see https://vueuse.org/useFirestore
*/
export function useFirestore<T extends DocumentData>(
maybeDocRef: MaybeRef<FirebaseDocRef<T> | false>,
maybeDocRef: MaybeRef<FirebaseDocRef<T> | Falsy>,
initialValue: any = undefined,
options: UseFirestoreOptions = {},
) {
Expand Down