Skip to content

Bug: @types/mongodb installed by Mongoose causing conflicts, Model Schema errors  #10535

@0x-cygnet

Description

@0x-cygnet

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
The Mongoose library installs the @types/mongodb library (deprecated) which now appears to be causing conflicts.

Possibly this is related to the work being done here?
DefinitelyTyped/DefinitelyTyped#54510

I am not able to compile code that has previously worked without issue and now get the following errors:

Screen Shot 2021-08-02 at 6 27 22 PM

Argument of type 'Schema<Document<any, any, any>, Model<any, any, any>, undefined, any>' is not assignable to parameter of type 'Schema<UserDoc, UserModel, undefined, unknown>'.
Types of property 'plugin' are incompatible.
Type '(fn: (schema: Schema<Document<any, any, any>, Model<Document<any, any, any>, {}, {}>, undefined, {}>, opts?: any) => void, opts?: any) => Schema<...>' is not assignable to type '(fn: (schema: Schema<UserDoc, Model<UserDoc, {}, {}>, undefined, {}>, opts?: any) => void, opts?: any) => Schema<UserDoc, UserModel, undefined, unknown>'.
Types of parameters 'fn' and 'fn' are incompatible.
Types of parameters 'schema' and 'schema' are incompatible.
Type 'Schema<Document<any, any, any>, Model<Document<any, any, any>, {}, {}>, undefined, {}>' is not assignable to type 'Schema<UserDoc, Model<UserDoc, {}, {}>, undefined, {}>'.
Types of property 'static' are incompatible.

It should be important to note that when I delete the node_modues/@types/mongodb directory in the local project (installed as a dependency by Mongoose) the type errors resolve.

Link to the failing code can be found here:
https://github.com/0x-cygnet/ticketing/blob/main/auth/src/models/user.ts

What is the expected behavior?
Should compile without errors as it did a week ago and no changes have been made to the codebase, repo or dependencies since.

What are the versions of Node.js, Mongoose, and MongoDB you are using? Note that "latest" is not a version.
Node = 16.3.0
npm = 7.6.3
Mongoose = 5.13.5 (upgraded from 5.12.11 and saw no difference or change in behavior).

Metadata

Metadata

Assignees

No one assigned

    Labels

    can't reproduceMongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions