denoland / fresh

The next-gen web framework.
https://fresh.deno.dev
MIT License
12.53k stars 648 forks source link

Dates (and other types) are serializable when using Deno KV but not islands #2325

Open skybrian opened 8 months ago

skybrian commented 8 months ago

Thought I'd describe something that's not exactly a bug, but can be confusing: there are differences between what can be serialized using Deno KV and what you can send to an island.

Let's say I have something like this:

type Message = {
  text: string,
  created: Date
}

This will serialize to Deno KV, but when I send it to an Island, the date will be converted to a string using Date's toJSON() method.

However, it type-checks fine. You won't notice any problem until runtime.

It would be convenient if the serialization used by islands were extended to dates and other types that KV can serialize. But when that's not feasible, it seems like there should be some kind of linter warning about types that won't serialize as you expect?

marvinhagemeister commented 8 months ago

Adding support for serializing days objects makes sense. We can't add long rules for this as it would require the linter to be aware of types, which it doesn't support. It just checks the AST tree.