Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
KikoCosmetics opened this issue Jan 11, 2025 · 0 comments
Open

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

KikoCosmetics opened this issue Jan 11, 2025 · 0 comments
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.

Comments

@KikoCosmetics
Copy link

KikoCosmetics commented Jan 11, 2025

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
}

@KikoCosmetics KikoCosmetics added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.
Development

No branches or pull requests

1 participant