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

TS error when specifying schema.pre 'deleteOne' with { document: true } #13601

Closed
2 tasks done
upirr opened this issue Jul 11, 2023 · 2 comments · Fixed by #13632
Closed
2 tasks done

TS error when specifying schema.pre 'deleteOne' with { document: true } #13601

upirr opened this issue Jul 11, 2023 · 2 comments · Fixed by #13632
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@upirr
Copy link

upirr commented Jul 11, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

7.3.2

Node.js version

16.18.1

MongoDB server version

4.4

Typescript version (if applicable)

5.1

Description

So basicallly specifying schema.pre('deleteOne', { document: true }, function() {}); will throw an error:

error TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type '"deleteOne"' is not assignable to parameter of type 'RegExp | "insertMany"'.

168  schema.pre('deleteOne', { document: true }, async function preHandler() {

Runtime-wise everything works though.

Steps to Reproduce

schema.pre('deleteOne', { document: true }, function() {});

Expected Behavior

No response

@vkarpov15 vkarpov15 added this to the 7.4.1 milestone Jul 12, 2023
@vkarpov15 vkarpov15 added has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue typescript Types or Types-test related issue / Pull Request labels Jul 12, 2023
@IslandRhythms
Copy link
Collaborator

import * as mongoose from 'mongoose';

const testSchema = new mongoose.Schema({
  name: String
});

testSchema.pre('deleteOne', { document: true }, function() {});

@IslandRhythms IslandRhythms added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue labels Jul 14, 2023
@vkarpov15
Copy link
Collaborator

vkarpov15 commented Jul 19, 2023

You can work around this by doing schema.pre('deleteOne', { document: true, query: false }, function() {}); . That compiles just fine.

vkarpov15 added a commit that referenced this issue Jul 20, 2023
types: correctly handle `pre('deleteOne', { document: true })`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants