Automattic / mongoose

MongoDB object modeling designed to work in an asynchronous environment.
https://mongoosejs.com
MIT License
26.76k stars 3.8k forks source link

mongoose.Types.ObjectId(string) - Expected 0 arguments, but got 1 #14694

Closed xiaojiudev closed 1 day ago

xiaojiudev commented 5 days ago

Prerequisites

Mongoose version

8.4.1

Node.js version

20.9.0

MongoDB server version

7.0.2

Typescript version (if applicable)

5.4.5

Description

My Deno project worked correctly until today I open my VSCode, it show a typescript error (my code still work correctly).

Screenshot 2024-06-28 090135

Steps to Reproduce

import mongoose from "npm:mongoose@8.4.1";

export const validObjectId = (id: string): boolean => {
    return mongoose.isValidObjectId(id);
};

export const generateObjectId = (id?: string): ObjectIdType => {
    if(id && validObjectId(id)) {
        return new mongoose.Types.ObjectId(id);
    } else {
        return new mongoose.Types.ObjectId();
    }
}

Expected Behavior

Typescript error should be hide

sieusanh commented 4 days ago

Hi @xiaojiudev, i tried running your code with all dependencies you have listed, except for MongoDB Server cause i think it's not necessary connecting to database.

Can you show your tsconfig.json and package.json file which includes mongoose and typescript related dependencies.

xiaojiudev commented 2 days ago

@sieusanh Here is my configuration in deno.json file (same as package.json), and I also defined typescript config in that file.

image

vkarpov15 commented 1 day ago

As a general rule, we don't debug errors that only show up in your IDE. If you're getting a build error when compiling your project we can look into it, but if it's just a VSCode warning the likelihood of us being able to repro it is negligible. For example, I don't get this warning on my machine:

image

Bamorem commented 22 hours ago

i'm getting the same error