Skip to content

plainToClass should always return a class-instance or throw #325

Open
@tmtron

Description

@tmtron

I think plainToClass should always reutrn a class-instance or throw an exception.

Here's a simple example where this is not the case (using version 0.2.3):

class Test {
  @IsString()
  readonly table!: string;
}
// note, that we call it with a completely wrong type: string instead of JSON-object
const result = plainToClass(Test, 'not a class');

Then result is of type string (value = 'not a class').

I'd expect plainToClass to:

  • return an instance of type Test where all properties remain undefined, or
  • throw an exception

Not sure, if this is a bug or intended - maybe there's a good reason for the current behaviour that I am missing?

see also Stackoverflow Question

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: featureIssues related to new features.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions