solenya-group / solenya

mega-powerful micro-framework
MIT License
81 stars 0 forks source link

Type decorator clarification? #7

Closed kylecordes closed 5 years ago

kylecordes commented 6 years ago

In the documentation, I see an example of the @Type() decorator. I understand the purpose of this decorator, to provide a hook to get type information to run time - TypeScript has lots of positive attributes, but it inconveniently doesn't have a feature to bring types along at runtime even if you want them.

export class Tree extends Component
{    
    @Type (() => Tree) trees: Tree[] = []
    ...
}

The confusing thing here though is that I would naïvely expect the code to look more like this:

export class Tree extends Component
{    
    @Type (() => Tree[]) trees: Tree[] = []
    ...
}

... Rather than automagically knowing when to treat the reference as an array rather than a single instance.

I understand this actually arrives from class-transformer, but a few words about it in the documentation would probably help understand it at a first glance.

solenya-group commented 6 years ago

Good point, and in fact when I used it first the time that was my expectation too. I'll revise the docs.

solenya-group commented 6 years ago

Here's the new property serialization section: https://github.com/pickle-ts/pickle#property-serialization

solenya-group commented 6 years ago

Also released an update to pickle that simplifies serialization, by preserving NaN values via decorating a property with @Num

solenya-group commented 6 years ago

Could still do a better job here more generally explaining class-transformer.

solenya-group commented 5 years ago

Since this was opened:

1) Non-undefined non-array properties are auto-decorated using initTransformers 2) The documentation has been updated.

Closing this issue, as the only improvement at this point would have to come from the typescript language itself automatically decorating properties based on their type.