firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.84k stars 889 forks source link

FR: Add generic support for firestore *.collection(...) methods. #7043

Open paulmand3l opened 1 year ago

paulmand3l commented 1 year ago

[REQUIRED] Describe your environment

[REQUIRED] Describe the problem

It would be convenient to be able to use generic types when getting collection references from firestore() and as subcollections of docRefs.

Steps to reproduce:

Get a collection from firestore or a docRef.

Relevant Code:

// Currently
const usersCollection = firestore().collection('users');
// usersCollection is CollectionReference<DocumentData>

// Desired
type User = {...};
const usersCollection = firestore().collection<User>('users');
// usersCollection is type CollectionReference<User>

Same for subcollections

ehsannas commented 1 year ago

Thanks for the suggestion @paulmand3l . We'll add this to our feature request list and consider it based on priority against other ones.

mikehardy commented 1 year ago

Hey @ehsannas - this has a linked PR so could just be merged if it seems okay - curious whether that's a possibility, if so what the thinking on timeline is. We've got a related PR lodged with react-native-firebase since we do our best to maintain type fidelity over there

ehsannas commented 1 year ago

This is similar to https://github.com/googleapis/nodejs-firestore/issues/1792. We're working on a fix that's larger in scope than the PR proposed above. I'll provide an update once our solution is merged/released. Thank you for your patience.

mikehardy commented 1 year ago

I see! Thanks for the update @ehsannas - @paulmand3l I think it will pay to wait on react-native-firebase then, so we do one typing change with an adoption of the final solution vs rushing with some half-thing

paulmand3l commented 1 year ago

👍🏻

On Sat, Mar 25, 2023 at 6:06 AM Mike Hardy @.***> wrote:

I see! Thanks for the update @ehsannas https://github.com/ehsannas - @paulmand3l https://github.com/paulmand3l I think it will pay to wait on react-native-firebase then, so we do one typing change with an adoption of the final solution vs rushing with some half-thing

— Reply to this email directly, view it on GitHub https://github.com/firebase/firebase-js-sdk/issues/7043#issuecomment-1483819373, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAC5LW7KRHG4FTOTIVXRIP3W53UT5ANCNFSM6AAAAAAU6TEH24 . You are receiving this because you were mentioned.Message ID: @.***>

-- Sent from my iPhone.