Skip to content

fix: plainToInstance is not working correcly #1744

Open
@ingrocha

Description

@ingrocha

Description

Every time I attempt to convert req.body using plainToInstance, it adds a field id:"".

Minimal code-snippet showcasing the problem

export class Note {
	@Exclude()
	id = '';

	@Expose()
	title = '';

	@Expose()
	content = '';

	author = '';

	@Expose()
	sharedUsers: SharedUsers[] = [];

	createdAt?: Date;
	updatedAt?: Date;
}

const noteInputDto = plainToInstance(Note, req.body, {
    excludeExtraneousValues: true
});

Expected behavior

{
    "title":"test",
    "content":"test",
    "sharedUsers":[]
}

Actual behavior

{
        "id": "",
        "title": "test",
        "content": "test",
        "sharedUsers": []
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs triageIssues which needs to be reproduced to be verified report.type: fixIssues describing a broken feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions