JairusSW / as-json

The only JSON library you'll need for AssemblyScript. SIMD enabled
MIT License
79 stars 15 forks source link

fix: 🐛 null value throwing for some json model (nested one) #44

Closed djang0dev closed 1 year ago

djang0dev commented 1 year ago

Hi! First thanks a lot for your works, the DX is really nicer than assemblyscript-json

Description

Just a quick fix about this stacktrace image

Certainly related to #28

For null values nested like this I had some TS errors :

{
  "operations": [
    {
      "expand": null,
    ...

Testing

Was unable to perform any kind of tests, tried to patch but it throws everywhere (is aspect really stable right now?)

JairusSW commented 1 year ago

First off, thank you. I would move https://github.com/JairusSW/as-json/blob/master/assembly/src/json.ts#L95 to the top of the condition chain and then use changetype<nonnull<T>>(); to convert string | null (or !) to string when it is guaranteed that data exists.

I believe a null check results in the compiler throwing a WARNING when string is not nullable, so its mainly just syntatical preference.

The tests do freak out like crazy. I'll have to look into that and see what is going on. It only happened when I updated as-pect, so that may be the problem.

JairusSW commented 1 year ago

Since it is just syntatical preference, I'm going to merge this. Thank you for the MR request

JairusSW commented 1 year ago

forgot to merge ._.