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

feat(NODE-3692): make change stream events typing more generic #3034

Merged
merged 6 commits into from Nov 10, 2021
Merged

Conversation

durran
Copy link
Member

@durran durran commented Nov 9, 2021

Added typescript generic typing to ChangeStreamEvents

Description

What changed?
The typing for ChangeStreamEvents was not generic, and did not contain <TSchema> so it was always assumed to be of type Document. This would affect code usage like this:

interface MyDoc extends Document{
   name: string
}
const client = new MongoClient('');
const coll = client.db('test').collection<MyDoc>('test');
coll.watch().on('change', c => c.fullDocument) 
// c.fullDocument above is typed as Document, but should be MyDoc

ChangeStreamDocument already had generic types, so I just passed through <TSchema>.

I tried it out locally and the typing showed correctly in my editor.

Could someone confirm that the init and more events do indeed return the same structure as TSchema, as I do not know what these events are?

@durran durran requested a review from nbbeeken November 10, 2021 12:52
test/types/mongodb.test-d.ts Outdated Show resolved Hide resolved
@durran durran requested a review from dariakp November 10, 2021 16:26
@dariakp dariakp merged commit d5ae78e into main Nov 10, 2021
@dariakp dariakp deleted the NODE-3692 branch November 10, 2021 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
4 participants