typestack / class-transformer

Decorator-based transformation, serialization, and deserialization between objects and classes.
MIT License
6.82k stars 500 forks source link

External Values are not stripped. #1642

Closed HaaLeo closed 11 months ago

HaaLeo commented 11 months ago

Description

This is a followup to #74. It appears the following does not work

Minimal code-snippet showcasing the problem

import 'reflect-metadata';
import { Expose, Exclude, plainToClass } from './index';

@Exclude()
class MyClass {
  @Expose()
  public propertyOne: string;

}

const instance = plainToClass(MyClass, {
  notAllowedValue: 'bad',
});

console.log(instance);
// returns MyClass { notAllowedValue: 'bad' }

Expected behavior

// returns MyClass { }

Actual behavior

// returns MyClass { notAllowedValue: 'bad' }
HaaLeo commented 11 months ago

Closing this. I've just opened it since I thought I could not comment on the original issue. I'll comment there instead.

HaaLeo commented 11 months ago

Mixing up issue references. Sorry. Therefore, reopening

HaaLeo commented 11 months ago

Ok turned out for me class-validator's whitelisting configuration does the trick for me as via https://github.com/typestack/class-transformer/issues/74#issuecomment-396230505

Now really closing the issue 😅

github-actions[bot] commented 10 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.