Skip to content

Feature Request: Make DocumentReference type generic #2504

@nathanosdev

Description

@nathanosdev

The DocumentReference type is wrapping the same type from firestore in a way that hides the generic type.

// original class
export class DocumentReference<T = DocumentData> {
  // ...
}

// angularfire's proxied type
export declare type DocumentReference = firestore.DocumentReference;

I would suggest also proxying the generic parameter like so:

export declare type DocumentReference<T = DocumentData> = firestore.DocumentReference<T>;

I didn't check everywhere that this model is used, but usages would also need to be adjusted. For example:

// current implementation
export class AngularFirestoreCollection<T = DocumentData> {
  add(data: T): Promise<DocumentReference>;
}

// my suggested change
export class AngularFirestoreCollection<T = DocumentData> {
  add(data: T): Promise<DocumentReference<T>>;
}

This would allow for much better type safety when working with the DocumentReference model.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions