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

types: improve lastErrorObject typing for rawResults #11602

Merged
merged 2 commits into from
Mar 31, 2022

Conversation

simllll
Copy link
Contributor

@simllll simllll commented Mar 30, 2022

Summary

This improves the type for lastErrorObject, this helps to use the correct values as there is for example no modifiedCount or other things that a simple updateOne returns.

Examples

// findOneAndUpdate with rawResult: true
const result = Model.findOneAndUpdate(query, { $inc: { occurence: 1 } },  { upsert: true, returnDocument: 'after', rawResult: true });

// should work
updateResult.lastErrorObject?.upserted
// should throw error
updateResult.lastErrorObject?.modifiedCount

@Uzlopak
Copy link
Collaborator

Uzlopak commented Mar 30, 2022

Hi Simon,

Lgtm. Could you please add your Sample Code to the typings Tests in test/types? I guess models.test.ts is the fitting file.

Maybe also add an error test?

Like
expectError(updateResult.lastErrorObject?.invalid);
?

Greetings from Teheran to Vienna :)

Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍
I second Uzlopak's comment, would be nice if we can have tests.

@simllll
Copy link
Contributor Author

simllll commented Mar 31, 2022

I've added a test in queries.test.ts as there are also some other similar tests in it already. Let me know if I should move it to models or another file if you think it fits better somewhere else.

Copy link
Collaborator

@Uzlopak Uzlopak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks 👍

@AbdelrahmanHafez AbdelrahmanHafez added the typescript Types or Types-test related issue / Pull Request label Mar 31, 2022
@AbdelrahmanHafez AbdelrahmanHafez added this to the 6.2.10 milestone Mar 31, 2022
@AbdelrahmanHafez AbdelrahmanHafez merged commit c7bd632 into Automattic:master Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants