fix: plainToInstance is not working correcly

Author: ingrochaCreated Aug 19, 2024Updated Oct 17, 2025
Labelstype: fixstatus: needs triage

Description

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

Minimal code-snippet showcasing the problem

typescript
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

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

Actual behavior

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

Source: typestack/class-transformer