Skip to content

Exposed "getters only" don't get handled in plainToInstance #1807

Open
@KikoCosmetics

Description

@KikoCosmetics

Description

It seems that using plainToInstance where you have a few getters (without setters) doesn't work.
I have this recollection where I converted responses in Angular and this used to work.
But I tried up to class-transformer 0.4.0 and it always behaves the same.

This is somewhat related (or clones) #1257

class ErrorResponse {
    @Expose()
    get errorCode(): number {
        return this._errorCode;
    }

    constructor(protected _errorCode: number = 800){}
}

plainToInstance(ErrorResponse, {
   "errorCode": 123
});

Blitz with full code here => https://stackblitz.com/edit/ts-class-transformer-issue

Expected behavior

I would expect to have

{
errorCode: 123
}

Actual behavior

{
errorCode: 800
}

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