Type arguments cannot be accepted in untyped function calls.ts(2347)

My user schema in typescript includes the following interface:

interface IUser{
  name: string;
  email: string;
  password: string;
  isAdmin: boolean;
}

Check out the user schema below:

const UserSchema = new Schema<IUser>(
 {
   name: {
     type: String,
     required: true,
   },
   email: {
     type: String,
     required: true,
     unique: true,
   validate: [validator.isEmail, "Please provide a valid email"],
   },
   password: {
     type: String,
     required: true,
     minlength: 8,
   },
   isAdmin: {
     type: Boolean,
     required: true,
     default: false,
   },
 },
   {
     timestamps: true,
   }
);

const UserModel = model("User", UserSchema);

module.exports = UserModel;

I encountered an error with typescript stating that untyped function calls may not accept type arguments on the user schema while using express and mongoose with visual studio editor.

Answer №1

It seems that the error is occurring at this particular line of code:

const UserSchema = new Schema<IUser>(

The error message states,

Untyped function calls may not accept type arguments
.

  • The issue lies with the type argument specified within the generic <...>.
  • Furthermore, the problem appears to be related to the unknown nature of the Schema function (which is currently typed as any).

This indicates a potential problem with either how you are importing the Schema, or with the installation of typings for mongoose.

I recommend reviewing the mongoose - TypeScript Support documentation for assistance.

If you're unable to resolve the issue, please provide us with the following information:

  • Your method of importing Schema
  • The versions of mongoose and possibly @types/mongoose that you are using

Answer №2

Upon following Stanislas' solution, I was able to resolve the issues I was experiencing.

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

interface ILink {
  discord_id: String;
  linking_code: String;
}

const LinkSchema = new Schema<ILink>({
    discord_id: {
        type: String,
        required: true,
        unique: [true, 'Discord ID name must be unique'],
    },
    linking_code: {
        type: String,
        required: true,
        unique: true,
    }
});

var Link = mongoose.model('Link', LinkSchema);
module.exports = Link;

I made adjustments to the imports as shown below:

import {Schema, model} from 'mongoose';

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

Should Mongoose Schemas be Created with or without the 'new' Keyword?

While browsing online, I have noticed that most examples demonstrate... var UserSchema = new mongoose.Schema({ name: String, age: String }); However, in a recent book I came across, the same code was written... but without including the new keywo ...

Using a pipe filter to implement a search feature in an Ionic search bar

Hey everyone, I'm facing a little issue here. I created a pipe filter to sort through some data, but now I need to include two more filters and I'm not sure how to go about it within this pipe. Below is an example of the pipe I have created: ...

The form post request cannot recognize the undefined variable

When attempting to send values through an HTML form and retrieve it in console.log, I encounter an error that says "TypeError: Cannot read property 'fName' of undefined," despite declaring it in the form name. signin.html : <!doctype html> ...

Enhance your FullCalendar experience with React by displaying extra information on your calendar

I am new to using React and FullCalendar, and I have a page layout similar to the image linked below. https://i.sstatic.net/MooTR.png Additionally, I have a list of events structured as shown: id: "9", eventId: "1", ...

Getting an image from a NodeJS backend to a React frontend

I successfully uploaded an image using the multer library in Express, storing it in the path Backend->Uploads/ and saving the image path in MongoDB. My project is structured as DirectoryName Backend Uploads Frontend While I can access the ima ...

What is the best way to calculate checksum and convert it to a 64-bit value using Javascript for handling extremely large files to avoid RAM overflow?

Question: What is the best method for generating a unique and consistent checksum across all browsers? Additionally, how can a SHA256/MD5 checksum string be converted to 64-bit? How can files be read without requiring excessive amounts of RAM when ...

Is there a bug in Model.save()?

For the freecodecamp test, I need to submit a name and save it to a collection. However, every time I click submit on my form, a lengthy warning message appears in the console: (node:20679) DeprecationWarning: Mongoose: mpromise (mongoose's default p ...

Typescript enables bidirectional control of Swiper

I attempted to use the two-way control slider example from Swiper documentation, but I encountered TypeScript errors that prevented it from working correctly. Is there a way to make it compatible with TypeScript? The specific errors I received were: TS23 ...

Develop a flexible axios client

I have a basic axios client setup like this: import axios from "axios"; const httpClient = axios.create({ baseURL: "https://localhost:7254/test", }); httpClient.interceptors.request.use( (config) => config, (error) => Prom ...

Obtain the query response time/duration using react-query

Currently utilizing the useQuery function from react-query. I am interested in determining the duration between when the query was initiated and when it successfully completed. I have been unable to identify this information using the return type or para ...

Utilize string variables within TypeScript's enumeration feature

Can string variables be used in enums in TypeScript? Strings can be used in enum like so: enum AllDirections { TOP = 'top', BOTTOM = 'bottom', LEFT = 'left', RIGHT = 'right', } However, trying to use variab ...

The dash symbol is crashing the express dot feature

While working with Node.js, Express, and DoT to parse a JSON structure, I encountered an error. The issue seems to be related to processing special characters within the JSON object provided... <td> {{= "Overview: " + record._source.explanation.ov ...

Is it possible to dynamically pass a component to a generic component in React?

Currently using Angular2+ and in need of passing a content component to a generic modal component. Which Component Should Pass the Content Component? openModal() { // open the modal component const modalRef = this.modalService.open(NgbdModalCompo ...

What is the best way to sort through an array depending on a specific sequence of elements provided

I am trying to create a custom pipe in Angular 5 that filters an array of events based on a given sequence. For instance, if my data is: ["submit", "click", "go_back", "click",...] I want to filter this data based on up to three inputs. If input ...

Tips for managing your time while anticipating an observable that may or may not

I am facing a dilemma in my Angular app where I need to conditionally make an HTTP call to check for the existence of a user. Depending on the result of this call, I may need to either proceed with another API request or halt the processing altogether. I ...

Struggling to properly import the debounce function in ReactJS when using TypeScript

I am facing an issue while trying to properly import the debounce library into my react + typescript project. Here are the steps I have taken: npm install debounce --save typings install dt~debounce --save --global In my file, I import debounce as: impo ...

Is there a way to display the items organized by category using mongoose?

Here is the schema I have created for storing products using Mongoose: const mongoose = require("mongoose"); const mongoosePaginate = require("mongoose-paginate-v2"); const productSchema = mongoose.Schema({ _id: mongoose.Schema.Types.Ob ...

Require type parameter to be of enum type

I have a specific goal in mind: // first.ts export enum First { One, Two, Three } // second.ts export enum Second { One, Two, Three } // factory.ts // For those unfamiliar, Record represents an object with key value pairs type NotWorkingType ...

The issue with Angular2 Material select dropdown is that it remains open even after being toggled

Exploring the world of Node.js, I am delving into utilizing the dropdown feature from Angular Material. However, an issue arises once the dropdown is opened - it cannot be closed by simply clicking another region of the page. Additionally, the dropdown lis ...

Express and subdomains for dynamic content only

How can subdomains be effectively managed using nodejs and express? Each subdomain will not contain static files like index.html, but rather pure code and logic. var express = require('express'), http = require('http'); var app = ...