Skip to content

FR: improve typing on CRUD methods #1496

Closed
@jorroll

Description

@jorroll

As a blanket concept, it would be very useful to update the SDK's document create and update methods to accept a type param to better type the passed in document argument.

For example, the first overload for the Firestore DocumentReference#update() method accepts a single firestore.UpdateData argument which is lightly typed.

Example usage:

documentRef.update(data.doc);

It would be awesome if a user could supply an optional type param to update which typescript would use to check the data.doc interface.

For example:

documentRef.update<{name: string; age: number}>(data.doc);

Typescript would ensure that data.doc had the interface {name: string; age: number}.

This general concept would be widely useful across the SDK and I do not think it would be a breaking change. My immediate desire is for Firestore related methods, but I believe the typing for the entire library could be improved in some places.

An implementation example for the first overload of the DocumentReference class:

update<T extends firestore.UpdateData = firestore.UpdateData>(value: T): Promise<void>;

Is this something you would accept PR's for?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions