typst-community / valkyrie

Type safe type safety for Typst
Other
22 stars 2 forks source link

Should coercions respect `optional: true`? #33

Open jneug opened 2 weeks ago

jneug commented 2 weeks ago

Not sure if this is intended, but currently coercions will panic if a value is none, which can happen with optional: true set.

I think it would be more intuitive, if a coercion respected the optional setting and returned none, if the key was not present.

For example, the array coercion would look like this:

#let array(self, it) = {
  if self.optional and it == none {
    return none
  }
  if (type(it) != type(())) {
    return (it,)
  }
  it
}
JamesxX commented 2 weeks ago

Good catch! I'm hoping to be able to put some time into this package this weekend and get the next version published.