question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AngularFire 7 Document Typing

See original GitHub issue

Have we lost document typing with the upgrade to AngularFire 7?

In the past, we were able to do (as shown in the docs) something like afs.doc<Item>('items/1') and that would return DocumentReference<Item> as the type.

Now it looks like the functions that exist are

function doc(firestore: types.FirebaseFirestore, path: string, ...pathSegments: string[]): DocumentReference<DocumentData>;
function doc<T>(reference: types.CollectionReference<T>, path?: string, ...pathSegments: string[]): DocumentReference<T>;
function doc(reference: types.DocumentReference<unknown>, path: string, ...pathSegments: string[]): DocumentReference<DocumentData>;

The only one that is typed is the one that takes in a previous collection reference. Meanwhile, this first is the one we’re directed to use in the upgrade documentation and it only uses DocumentData. One of the big benefits to using AngularFire previously over the vanilla Firebase libraries was the fact that DocumentData didn’t have to be cast. Has that now been removed?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
Methodiciancommented, Oct 5, 2021

@jamesdaniels does this mean we will eventually get functionality in line with the current documentation, or that the documentation will be updated to reflect the new (seemingly downgraded) doc and collection type setting?

3reactions
jamesdanielscommented, Sep 8, 2021

It seems Firestore isn’t allowing one to override the typings, only allowing types to be inferred if using a converter. Converters are “better” in the sense that you can have real run-time checks to guard you against data that doesn’t conform to your expectations but they can be overly verbose.

const fooCollection = collection(firestore, 'foo').withConverter({
  toFirestore(data) => ({ ...data }),
  fromFirestore(snapshot) => new Foo(..),
})

return collectionData(fooCollection); //=> Observable<Foo[]>

I’ll address in a future release of Angular/RxFire.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get a typed object with angularfire 7+ (firebase 9)
The easiest solution is just to cast your document reference like this: const docReference = doc( this.firestore, 'queues/' + userId ) as ...
Read more >
Developers - AngularFire 7 Document Typing - - Bountysource
Coming soon: A brand new website interface for an even better experience!
Read more >
Creating CRUD Firebase documents in Angular
This extensive tutorial shows you how to Create, Read, Update, and Delete (CRUD) Firebase documents in Angular.
Read more >
Angular 13 Firebase Authentication Tutorial With AngularFire 7
ts file. Adding routes the app-routing module. Note that we're adding a wildcard route, that ...
Read more >
Angular 7 CRUD using Firestore - YouTube
Angular 7 CRUD operations implemented using FirestoreIn this lesson, ... After selecting a record user can update a Firestore document.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found