Support for transformation of nullable fields
dotslashx opened this issue · 0 comments
dotslashx commented
Is your feature request related to a problem? Please describe.
I am unable to use the PropertyType
decorator for property which may be null
or undefined
.
Describe the solution you'd like
The solution might be as simple as adding the enabled
option behaving exactly the same as it does in the MapFromSource
decorator but independently of each other
Additional context
Simple example of the problem:
class Foo {
@MapFromSource(obj => obj.anything)
public something!: string;
}
class Bar {
@PropertyType(Foo)
@MapFromSource(obj => obj.maybeFoo)
public foo!: Foo | null;
}
This one works as expected:
mapClasses({
maybeFoo: {
anything: 'whatever'
}
}, Bar);
But this one:
mapClasses({
maybeFoo: null
}, Bar);
Throws an error, however i would expect the result to be this:
{
foo: null
}