The @IsEnum function does not support converting undefined or null values to objects

When I tried to use the IsEnum class validator in the code snippet below:

export class UpdateEvaluationModelForReportChanges {
  @IsNotEmpty()
  @IsEnum(ReportOperationEnum)    // FIRST
  operation: ReportOperationEnum;

  @IsNotEmpty()
  @IsEnum(EvaluationStatusEnum).  // SECOND
  status: EvaluationStatusEnum;
  // ...
}

I encountered an error with the second IsEnum decorator:

../node_modules/src/decorator/typechecker/IsEnum.ts:18
  return Object.entries(entity)
                ^
TypeError: Cannot convert undefined or null to object

The first enum, ReportOperationEnum, is defined in the same file as the class. Here is its definition:

// ...
export enum ReportOperationEnum {
  COMPLETED = "COMPLETED",
  REVIEWED = "REVIEWED",
  RETURNED = "RETURNED",
}
// ...

The second enum, EvaluationStatusEnum, is in a separate file:

// ...
export enum EvaluationStatusEnum {
  CANCELED = 'CANCELED',
  SCHEDULED = 'SCHEDULED',
  FINISHED = 'FINISHED',
}
// ...

Merging the second enum into the file with the first enum solves the issue, but I would like to avoid duplicating or moving the second enum from its original location. Both enums are part of files that contain other enums and classes. Could there be any reasons or factors causing this problem?

Answer №1

The issue has been successfully resolved. It seemed to be linked to the placement of the second enum, EvaluationStatusEnum, which was located within the file that was exporting the schema:

export enum EvaluationStatusEnum {
    // ...
}
@Schema()
export class Evaluation extends BaseModel implements EvaluationModel {
    // ...
}
export const EvaluationSchema = SchemaFactory.createForClass(Evaluation);

After moving the enum to a separate file dedicated solely to enums, the errors disappeared.

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

Quickest method for sorting an array of objects based on the property of another object's array

Within my code, I have two arrays of objects, both containing a "columnId" property. My goal is to rearrange the first array to match the order of the second. I attempted the following method: filtered = visibleColumns.filter(function(v) { re ...

Removing duplicate elements from an array in TypeScript

In my TypeScript code, I am working with an array of objects and need to remove any duplicates. The code below accomplishes this task: const uniqueObjects = Array.from(new Set(nonUniqueObjects.map((x) => { return JSON.stringify(x); }))). ...

Using Javascript or ES6, you can compare a nested array object with another array of elements and generate a new array based on

I am dealing with a complicated array structure as shown below sectionInfo = [{id: 1, name:'ma'}, {id: 2, name:'na'}, {id: 3, name:'ra'}, {id: 4, name:'ka'}, {id: 5, name:'pa'}]; abc = [{id:'1' ...

Tips on efficiently reusing shared components within recursive union types in TypeScript

Summary Here's a simple working example in the TypeScript playground: type SimpleExpression = number | string | AddOperator<SimpleExpression> | PrintOperator<SimpleExpression>; type ExtendedExpression = number | string | AddOperator<E ...

What is the reason behind the mandatory credentials option for the CredentialsProvider?

When using NextAuth.js with a custom sign in page, some code examples for the credentials provider do not include the credentials option in the CredentialsProvider. According to the documentation (here), the credentials option is meant to automatically "ge ...

Establishing an efficient development environment with continuous integration for react-native using typescript and nodejs

Unfortunately, we encounter the challenge of working with different nodejs versions in our projects. I am unsure if this is similar to Java where multiple jdks can be installed (multiple nodejs installations), and each project automatically utilizes the co ...

Angular 6 and above: The use of ProvidedIn in a submodule is leading to a circular dependency issue

A resolve service is being implemented using the new providedIn attribute. This translations resolver is utilized in a protected module: import { Injectable } from '@angular/core'; import { Observable , pipe } from 'rxjs'; import { ...

Can we guarantee the uniqueness of a function parameter value during compilation?

I have a set of static identifiers that I want to use to tag function calls. Instead of simply passing the identifiers as arguments, I would like to ensure that each identifier is unique and throws an error if the same identifier is passed more than once: ...

The RxJS observable fails to initiate the subscribe function following the mergeMap operation

I am attempting to organize my dataset in my Angular application using the RxJS operators and split it into multiple streams. However, I am facing difficulties making this work properly. Inside my SignalRService, I have set up a SignalR trigger in the cons ...

Can you explain the concept of being "well-typed" in TypeScript?

The website linked below discusses the compatibility of TypeScript 2.9 with well-defined JSON. What exactly does "well-typed" JSON mean? As far as I understand, JSON supports 6 valid data types: string, number, object, array, boolean, and null. Therefore, ...

Incorporate an HTML span element with an onclick function bound in Angular framework

Is there a way to incorporate different icons by adding a span based on a flag, with an onclick event that triggers an internal function defined in the component ts? testfunc(){ console.log("it works") } flagToIcon(flag: boolean) { switch ( ...

Guide to integrating a native web component into Vue3

After creating the renderComponent method to display a webcomponent, I attempted to use it in my componentView.vue file. export function renderComponent(el: Element, component: Component,props: VNodeProps,appContext: AppContext){ let vnode: VNode | undefin ...

Guide on assigning a value to an object array within an Angular application

I need help figuring out how to update a value in an object array. The current object array is structured like this: objArr = [ { "id": "123", "name": "abc" }, { "id": "null", "name ...

Displaying a collection of objects in HTML by iterating through an array

As someone new to coding, I am eager to tackle the following challenge: I have designed 3 distinct classes. The primary class is the Place class, followed by a restaurant class and an events class. Both the restaurant class and events class inherit core p ...

One-Of-A-Kind Typescript Singleton Featuring the Execute Method

Is it feasible to create a singleton or regular instance that requires calling a specific method? For instance: logger.instance().setup({ logs: true }); OR new logger(); logger.setup({ logs: true }); If attempting to call the logger without chaining the ...

Issues arise when Angular properties become undefined following the initialization or OnInit functions

There seems to be a peculiar issue with the properties of an angular component that I have set up. It appears that these properties are losing their values after the initialization process. The component is essentially a basic HTML file containing a video ...

Is it possible to derive a TypeScript interface from a Mongoose schema without including the 'Document' type?

Using ts-mongoose allows me to define interfaces and schemas for my data in one place. I then export them as a mongoose schema along with the actual interface. The challenge I'm facing is finding a simple way to extract that interface without includi ...

Having trouble importing a file in TypeScript?

I needed to utilize a typescript function from another file, but I encountered an issue: I created a file called Module.ts with the following code snippet: export function CustomDirective(): ng.IDirective { var directive: ng.IDirective = <ng.IDire ...

Transferring the date from an HTML input to a TypeScript file in Angular when the button

On my HTML page, I have two input fields for dates that need to be passed to the backend along with other parameters when a button is clicked. Here is the current setup: <input [owlDateTime]="dt1" placeholder="From a date" [value]="dateFrom.value"& ...

Tips for effectively passing navigation as props in React Navigation with Expo

How can I correctly pass navigation as props to another component according to the documentation? The navigation prop is automatically provided to each screen component in your app. Additionally, To type check our screens, we need to annotate the naviga ...