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": []
}

Activity

added
status: needs triageIssues which needs to be reproduced to be verified report.
type: fixIssues describing a broken feature.
on Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @ingrocha

        Issue actions

          fix: plainToInstance is not working correcly · Issue #1744 · typestack/class-transformer