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

Expose generic types of @google-cloud/firestore #1229

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mamichels
Copy link

This exposes the already existing generic types of @google-cloud/firestore for DocumentSnapshot and QueryDocumentSnapshot.
I've also added the default to not introduce any breaking change and keep the typing optional. In regard to less readable documentation and a cleaner implementation I've also added the default type DocumentData as an exposed type.

Currently you cannot even overwrite QueryDocumentSnapshot with the generic type of @google-cloud/firestore since the handler will not accept the same as it uses an internal reflected type of QueryDocumentSnapshot. Hence an explicit type cast needs to be placed during unwrapping. E.g.

import { firestore } from './src';
import { EventContext } from './src/cloud-functions';
import { QueryDocumentSnapshot } from './src/providers/firestore';

interface MyDocument {
    foo: string;
}

export const firebaseFunction = firestore
    .document('{collection}/{id}')
    .onCreate(async (data: QueryDocumentSnapshot, context: EventContext) => {
        // I don't want that 😥
        console.log('data: ' + (data.data() as MyDocument).foo);
    });

This change will enable the following implementation:

import { firestore } from './src';
import { EventContext } from './src/cloud-functions';
import { QueryDocumentSnapshot } from './src/providers/firestore';

interface MyDocument {
    foo: string;
}

export const firebaseFunction = firestore
    .document('{collection}/{id}')
    .onCreate(async (data: QueryDocumentSnapshot<MyDocument>, context: EventContext) => {
        // It works! 🥰
        console.log('data: ' + data.data().foo);
    });

If you need me to make any changes please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant