Error in Typescript: 2 arguments were provided instead of the expected 0-1 argument

When attempting to run a mongoose schema with a timestamp, I encountered an error:

error TS2554: Expected 0-1 arguments, but got 2.

  { timestamps: true }

Below is the schema code:

const Schema = mongoose.Schema;
const loginUserSchema = new Schema(
 {
    userId: { type: String, required: false }
 },
  { timestamps: true }
);

loginUserSchema.index({ userName: 'text' });

export const LoginUserModel = mongoose.model("loginUser", loginUserSchema) ;

Here is my package.json:

  "dependencies": {
    "@types/express": "^4.17.9",
    "@types/mongoose": "^5.7.7",
    "@types/node": "^13.9.2",
    "@types/react-router-dom": "^5.1.3",
    "body-parser": "^1.13.3",
    "config": "^3.3.2",
    "cors": "^2.8.1",
    "express": "^4.13.3",
    "express-session": "^1.14.2",
    "jsonwebtoken": "^8.5.1",
    "keycloak-connect": "github:keycloak/keycloak-nodejs-connect",
    "moment": "^2.29.1",
    "mongodb": "^3.5.5",
    "mongoose": "^5.10.9",
    "nodemon": "^2.0.5",
    "react-router-dom": "^5.1.2",
    "socket.io": "^2.3.0",
    "ts-node": "^8.10.2",
    "typescript": "^3.9.7"
  }

Are there any changes I should make to get this working?

Answer №1

It appears there could be a flaw in the @types/mongoose library.

Try using:
loginUserSchema.set('timestamps', true)

As a workaround.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Attempting to insert the symbol "$gt" into a query for a search. {[CastError: Unable to convert value "[object Object]" to date at path "createdAt"]}

In the following code snippet: Reviews.find({createdAt : {"$lt" : app.locals.lastDate}}), I am trying to dynamically change the $lt to $gt. app.post("/scroll", function(req, res){ console.log("req.body...", req.body); var sortCreate = req.body.old ...

What is the best way to verify if a text input has a valid email format in ReactJS?

When working with ReactJS, how can I properly check if text entered in a <TextField/> component is in email format (i.e. contains @)? Since my application is connected to MongoDB, should I perform the email format validation on the client-side or se ...

Eliminating data type from union in Typescript

I have a specific type that I collect from various other types: type CustomType = { id: string; foo: (string | Type1)[]; bar: (string | Type2)[]; baz: string | Type3 | null; description: string | null; } I am interested in refining thi ...

Using the .skip() method in MongoDB to return specific results

Hey there, I've got a quick theoretical question for you. When using MongoDB and executing a command like db.collection.find().skip(1000) Does it only return the objects starting from the 1000th position to the end of the collection, or does it loo ...

Unable to access or modify properties within a function passed as an argument

deleteDialog(item, func: Function) { this.dialogService .open(ConfirmDialogComponent, { context: { title:"Are you sure?", cancelClss: "info", confirmClss: "danger", }, ...

Use Angular's super.ngOnDestroy method for handling cleanup/unsubscribing

When it comes to unsubscribing / cleaning up from observables in Angular components (using ngOnDestroy), there are multiple options available. Which option should be considered the most preferable and why? Also, is it a good practice to include super.ngOnD ...

The 'changes' parameter is inherently defined with an 'any' type.ts(7006)

Encountering an error and seeking help for resolution. Any assistance would be highly appreciated. Thank you. Receiving this TypeError in my code. How can I fix this issue? Your guidance is much appreciated. https://i.sstatic.net/cWJf4.png ...

Encountering difficulty when integrating external JavaScript libraries into Angular 5

Currently, I am integrating the community js library version of jsplumb with my Angular 5 application (Angular CLI: 1.6.1). Upon my initial build without any modifications to tsconfig.json, I encountered the following error: ERROR in src/app/jsplumb/jspl ...

Is there a way to set the initial value of an input's ngmodel variable using only HTML?

Is there a way to assign an initial value of "1" to the variable named "some" using ngModel during initialization? *Update: I am specifically interested in how to achieve this using HTML only component.html : <input type="text" value="1" name="some" ...

Challenges with formArrayName in Angular can be tricky to navigate

I am in the process of developing an Angular library with the main feature being the provision of a selector with two inputs: a reactive form containing the data an object literal specifying which properties of the data should have editable input fields ...

Ways to get into the Directive class

@Directive({ selector: '[myHighlight]' }) export class HighlightDirective { static test: number = 5; constructor(private el: ElementRef) { } highlight(color: string) { this.el.nativeElement.style.backgroundColor = color; } } In re ...

What could be causing the error that pops up every time I attempt to execute a git push

When I executed the following command in git git push origin <the-name-of-my-branch> I encountered the following warning message Warning: The no-use-before-declare rule is deprecated since TypeScript 2.9. Please utilize the built-in compiler check ...

Encounter an 'expected comma' error when using the User.findOne() function

Currently, I am developing an Express server tailored for authentication using MongoDB. Unfortunately, I have encountered a perplexing error that seems to keep recurring. Despite my best efforts, I cannot pinpoint the root cause of this issue. Could someon ...

Error with Typescript types when using Styled Components

After successfully setting up styled-components in react-native, I encountered an issue while trying to use it in a simple example with react-native-web: import * as React from 'react'; import styled from 'styled-components'; export d ...

Restrictive discriminated union via function argument

I am in possession of a shop that organizes a variety of types based on their IDs interface Dog { type: "dog"; woofs: string; } interface Cat { type: "cat"; meows: string; } type Pet = Dog | Cat; type AnimalState = Record<string, Pet ...

Tips for transferring request variables/data from a middleware to another function in typescript

I need to authenticate a user's jwt token using middleware. This is the middleware I have: const authorized = (req: Request, res: Response, next: NextFunction) => { const token = req.header("token") if(!token){ return res.send("N ...

How to eliminate the button from Google Maps API using JavaScript

I am trying to implement a specific functionality on my map. When the user drags the map, I want a button named 'Search in this area' to appear. Once the user clicks on the button, it should disappear so that the search can't be performed ag ...

When clicking the button, the service function is not properly updating the view

Upon calling this.getLeaderboard(); in the ngOnInit() function within leaderboard.component.ts, the leaderboard is only displayed on page load or refresh, which is expected. However, I also want to retrieve and display the leaderboard upon clicking a butto ...

Refreshing the page does not trigger Angular callHooks

Encountering an issue with the proper invocation of F5 button or directive call URL from the address bar resulting in ngOnInit not being triggered correctly. Using a debugger to analyze the situation, it was noticed that callHook is not initiated after ngO ...

Is the array index a string or a number?

Why is it that when looping over the indexes of an array they appear as strings, even though using a string to index an array is not allowed? Isn't this inconsistency puzzling? for (const i in ["a", "b", "c"]) { console.log(typeof i + " " + i + " " ...