NestJS service does not support DTO functionality

In my situation, I am using a DTO that looks like this:

export class CreatePlotDTO {
  @IsNumber()
  @ApiProperty()
  @IsOptional()
  area: number;

  @IsNumber()
  @ApiProperty()
  @IsOptional()
  ownerID: number;
}

I also have a method named create. UPDATE: This method is located in the plotService and it accepts the above mentioned dto.

async createPlot(plot: CreatePlotDTO) {
  return this.plotModel.create(plot)
}

Everything was working smoothly until recently when an error started occurring:

Argument of type 'CreatePlotDTO' is not assignable to parameter of type 'CreationAttributes<Plot>'.
      Type 'CreatePlotDTO' is not assignable to type 'Omit<any, string>'.
        Index signature is missing in type 'CreatePlotDTO'.

My suspicion is that the problem lies within either "sequelize": "^6.16.2" or "sequelize-typescript": "^2.1.3". Any ideas on how to resolve this issue?

Answer №1

I encountered a similar issue while using the versions ("sequelize": "^6.16.2" or "sequelize-typescript": "^2.1.3"). It seems like there may be an issue with either of these two versions. However, I found a workaround that involves the following steps:

  1. Ensure your model is defined as shown below:
@Table
export class Plot extends Model<Plot> {
    ...
}

(pay attention to the <Plot> part).

  1. Convert your DTO instance to the actual model type:
async createPlot(plot: CreatePlotDTO) {
    return this.plotModel.create(plot as Plot)
}

(note the as Plot part).

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

IntelliSense for TypeScript Variable Names in Intellij

When declaring a variable or field in Java, it is common practice to specify the type. For example: public SomeDataType someDataType = new SomeDataType(123) As you begin typing Som.., IntelliJ's autocomplete feature will likely suggest SomeDataTyp ...

You are unable to apply 'use client' on a layout element in Next.js

While attempting to retrieve the current page from the layout.txt file, I encountered errors after adding 'use client' at the top of the page: Uncaught SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data parseMod ...

Utilizing the NestJS Reflector within a Custom Decorator: A Comprehensive Guide

I have implemented a solution where I use @SetMetaData('version', 'v2') to specify the version for an HTTP method in a controller. Additionally, I created a custom @Get() decorator that appends the version as a suffix to the controller ...

What is the best way to create a generic that can handle readonly types efficiently?

When performing an action on a list type PerformActionOn<L extends any[]> = L The approach I am taking is as follows: const keys = { a: ['a', 'b', 'c'] as ['a', 'b', 'c'], d: ['d ...

Angular 7 router navigate encountering a matching issue

I created a router module with the following configuration: RouterModule.forRoot([ {path: 'general', component: MapComponent}, {path: 'general/:id', component: MapComponent}, {path: '', component: LoginComponent} ]) Sub ...

Issues arise as a result of conflicts between the dependencies of @ionic/angular, Angular 13, typescript,

Current Environment Details: ionic info Ionic: Ionic CLI : 6.18.1 (/usr/local/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/angular 5.8.5 @angular-devkit/build-angular : 13.0.2 @angular-devkit/schemat ...

Choose particular text within the editorState

I'm in the process of developing a sophisticated text editor utilizing draftjs. Take a look at this basic codesandbox to get a better understanding of the issue at hand. One of the challenges I'm facing is with a helper function called getCurren ...

Having trouble with routerLink in your custom library while using Angular 4?

In my Angular 4 project, I have developed a custom sidebar library and integrated it into the main project. My current issue is that I want to provide the option for users to "open in new tab/window" from the browser's context menu without having the ...

Overriding the 'first' attribute in PrimeNG's lazy table when implementing filtering

I encountered an issue while attempting to set up a primeNG table using query parameters. For example, when accessing , the data displayed should pertain to "Joe" and start at the 20th entry. To handle the large volume of data my backend can provide, lazy ...

Having trouble with TypeScript in react-select - Error: Generic type 'ValueType' needs 2 type arguments

Looking to implement the react-select package, I have the code snippet below: import React, {useState} from 'react'; import LanguageChange from '../../../Icons/LanguageChange'; import Select, { ValueType } from 'react-select'; ...

Converting the information retrieved from Firebase into a different format

My Project: In my Angular SPA, I am trying to retrieve data from Firebase and display specific values on the screen. Approach Taken: The data returned from Firebase looks like this: Returned Data from Firebase Error Encountered: In order to display the ...

Angular Error: Attempting to access property 'then' of undefined object causes TypeError

I am struggling with implementing JHipster Auth-guard. I am facing an issue where canActivate is not triggered for a user without permission for a specific route. I have carefully examined my code, but the console shows that .then() is undefined at the sp ...

Learn how to efficiently disable or enable a button in Angular depending on the selected radio button

In order to disable the button when the remarks are marked as failed. Here is an example scenario: Imagine there is an array containing two to four items. First example: ITEM 1 -> FAILED -> Remarks (required) ITEM 2 -> FAILED -> Remarks (r ...

Is it possible that using npm link could be the root cause of the "module not

As I delve into understanding how to utilize TypeScript modules in plain JavaScript projects, it appears that I am facing a limitation when it comes to using npm linked modules. Specifically, I can successfully use a module that is npm-linked, such as &apo ...

Encountering a Runtime Exception while utilizing MapQuest's direction routing feature on Ionic 3

I have successfully generated a map using the Ionic 3 framework, but I encountered a runtime error when attempting to use the L.mapquest.directions().route() function. Here are the imports: <link rel="stylesheet" href="https://unpkg.com/ ...

I encountered an issue while generating a crypto address on the Waves blockchain using the @waves/waves-crypto library in TypeScript

Encountering an issue with finding "crypto-js" in "@waves/waves-crypto". Despite attempts to uninstall and reinstall the module via npm and importing it using "*wavesCrypto", the error persists within the module's index.d.ts file. I am attempting to ...

Importing dynamically into Ionic 2 from locations other than the "node_modules" directory

I've recently reviewed the documentation for ModuleResolution in TypeScript on this page: https://www.typescriptlang.org/docs/handbook/module-resolution.html#node My understanding is that all files I wish to import must reside within the node_modules ...

Having trouble transferring data using HttpClient in Angular 4 with a Symfony backend

Resolved using NelmioCorsBundle. I am currently utilizing angular 4.3.3 for the front end and Symfony3 for the backend, with the addition of FosRestBundle. When working with Angular, I primarily use HttpClient to handle data request and transmission. Da ...

Is using $timeout still considered the most efficient method for waiting on an Angular directive template to load?

When it comes to waiting for a directive's template to render, our team has been following the approach of enclosing our DOM manipulation code in a $timeout within the directive's link function. This method was commonly used in the past, but I&ap ...

The `$refs` variable in Vue can be used to reference a specific Vue component within a class-st

Would it be possible to access this.$refs.label? I am using the package vue-property-decorator. Below is the content of the component: <template> <div> <label ref="label">asd</label> </div> </template> <scr ...