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 #2990

Closed
wants to merge 2 commits into from
Closed

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

wants to merge 2 commits into from

Conversation

mrbrianevans
Copy link
Contributor

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?

Added typescript generic typing to ChangeStreamEvents
@durran durran changed the title Added event typing for change streams feat(NODE-3692): make change stream events typing more generic Oct 19, 2021
@durran durran added Primary Review In Review with primary reviewer, not yet ready for team's eyes tracked-in-jira Ticket filed in MongoDB's Jira system labels Oct 19, 2021
@durran durran assigned durran and unassigned durran Oct 19, 2021
src/change_stream.ts Outdated Show resolved Hide resolved
@durran
Copy link
Member

durran commented Nov 9, 2021

Verified init and more events are returning the command response, which I believe can be TSchema in these cases.

@durran durran self-requested a review November 9, 2021 15:10
@durran
Copy link
Member

durran commented Nov 9, 2021

I've added type tests and opened #3034 to replace this PR.

@durran durran closed this Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Primary Review In Review with primary reviewer, not yet ready for team's eyes tracked-in-jira Ticket filed in MongoDB's Jira system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants