solenya-group / solenya

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

Number Deserialization #8

Closed solenya-group closed 6 years ago

solenya-group commented 6 years ago

The class-transformer library converts NaN values to null values. This is documented, but it's not ideal. The work around is currently to use the attached method on component as follows:

class MyComponent {
  myNum = NaN

  attached () {
    this.myNum = this.myNum == null ? NaN : this.myNum
  }

Potentially a better solution is given a numeric type annotation like this:

  @Type (() => Number)  myNum = NaN

That pickle would, upon deserialization, automatically convert the null to NaN.

solenya-group commented 6 years ago

Implemented & documented. Use the @Num decorator:

class MyComponent {
  @Num myNum = NaN
}