Closed mattjohnsonpint closed 1 year ago
Ah, just noticed the detail of the error. It's because I'm using the AssemblyScript WASI Shim. If I remove it, then it compiles.
Any ideas how to work around?
Looks like I can switch back to the normal Date
object with:
import { Date } from "date";
Of course that means I can only use the original implementation of Date.now
, instead of the WASI implementation, but I think I can just ensure my host exports Date.now
properly and ignore that aspect of WASI. (Or just get rid of WASI altogether, perhaps.)
Yeah, I have run into this problem before. I'll look into it though. I believe it has something to do with the transform using Date
and then the compiler's pass overriding Date
to wasi_Date
. I'd recommend you ask in the assemblyscript discord server though
Can you import the wasi_Date directly?
import { Date as wasi_Date } from "@assemblyscript/wasi-shim/assembly/wasi-date"
https://github.com/AssemblyScript/wasi-shim/blob/4399cffa93a70da3a48b30c55d90414be7ec8dc0/assembly/wasi_date.ts#L15
Actually, I acted to soon to close the issue. Even without the WASI shim, I still can't deserialize an object containing a date to a Date
field. It compiles fine, but at runtime, I get:
abort: Could not deserialize data 2023-11-16T04:06:35.108285303Z to type Date. Make sure to add the correct decorators to classes. in ~lib/json-as/assembly/src/json.ts(297:5)
Can you import the wasi_Date directly?
Doesn't help. It's not the Date
type that as-json
uses, so it's mismatched. But as I said, I can live without the WASI implementation. I just need it to work with the regular Date
object without giving an error. Thanks.
Fixed this problem in https://github.com/JairusSW/as-json/commit/2c07ef2dd8eeee1bf4a3d95c2316a6d9709bd2db Changes are live on NPM (v0.6.0)
Fixed.
I tested and it works, but I don't think you want to pull in the whole date parser. Please consider #55 instead.
In particular, the date parsing logic has some errors when presented with strings having more than 3 decimal places of fractional seconds. It also doesn't handle ISO strings containing time zone offsets. Both of those issues are better handled in the AssemblyScript repo. I'll send a PR there. Thanks.
FYI - I sent a PR to AssemblyScript to fix the issues I mentioned. https://github.com/AssemblyScript/assemblyscript/pull/2803
Merged and published
According to #35 - we should have support for
Date
types implemented. But this doesn't work:When compiling, I get: