Navigation Menu

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

Incorrect types for $pull since 6.4.0 #12142

Closed
2 tasks done
wight554 opened this issue Jul 22, 2022 · 1 comment
Closed
2 tasks done

Incorrect types for $pull since 6.4.0 #12142

wight554 opened this issue Jul 22, 2022 · 1 comment
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@wight554
Copy link

Prerequisites

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

Mongoose version

6.4.6

Node.js version

16.14

MongoDB server version

5.0.9

Description

When trying to remove item from one-to-many relation array usingh $pull getting the following type error:

C:\Users\wight\Documents\blog-template\node_modules\ts-node\src\index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
server/comment/CommentService.ts:117:9 - error TS2345: Argument of type '{ $pull: { comments: string; }; }' is not assignable to parameter of type 'UpdateWithAggregationPipeline | UpdateQuery<PostDocument> | undefined'.
  The types of '$pull.comments' are incompatible between these types.
    Type 'string' is not assignable to type 'FilterOperators<undefined> | Partial<Comment | undefined> | { text?: FilterOperators<string> | undefined; author?: FilterOperators<...> | undefined; ... 4 more ...; updatedAt?: FilterOperators<...> | undefined; }'.

117         {
            ~
118           $pull: { comments: commentId },
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
119         },
    ~~~~~~~~~

    at createTSError (C:\Users\wight\Documents\blog-template\node_modules\ts-node\src\index.ts:859:12)
    at reportTSError (C:\Users\wight\Documents\blog-template\node_modules\ts-node\src\index.ts:863:19)
    at getOutput (C:\Users\wight\Documents\blog-template\node_modules\ts-node\src\index.ts:1077:36)
    at Object.compile (C:\Users\wight\Documents\blog-template\node_modules\ts-node\src\index.ts:1433:41)
    at transformSource (C:\Users\wight\Documents\blog-template\node_modules\ts-node\src\esm.ts:400:37)
    at C:\Users\wight\Documents\blog-template\node_modules\ts-node\src\esm.ts:278:53
    at async addShortCircuitFlag (C:\Users\wight\Documents\blog-template\node_modules\ts-node\src\esm.ts:409:15)
    at async ESMLoader.load (node:internal/modules/esm/loader:359:20)
    at async ESMLoader.moduleProvider (node:internal/modules/esm/loader:280:47) {
  diagnosticCodes: [ 2345 ]
}

Originally reported here: #12049 (comment)

Steps to Reproduce

project link: wight554/blog-template#55
code snippet:

  PostModel.updateOne(
    { _id: postId },
    {
      $pull: { comments: commentId },
    },
    { useFindAndModify: false },
  );

Expected Behavior

No response

@IslandRhythms IslandRhythms added the typescript Types or Types-test related issue / Pull Request label Jul 22, 2022
@vkarpov15 vkarpov15 added this to the 6.4.8 milestone Jul 25, 2022
@Airboy
Copy link

Airboy commented Jul 27, 2022

It seems that the $push operator is broken too. Here is the error I faced while upgrading from 6.3.8 to 6.5.0:

error TS2322: Type 'PictureType[]' is not assignable to type 'PictureType | ArrayOperator<PictureType[]>'.

// Code
await Model.updateOne({ _id }, { $push: { pictures } });

Could it be related to this commit 9524f89 @vkarpov15 ?

Note that it works with 6.3.9 but starts to break from 6.4.0 (as mentioned by @wight554)

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

No branches or pull requests

4 participants