The opt t type contains all the values of type t , plus the special null value. It is used to express that some value is optional, meaning that data might be present as some value of type t , or might be absent as the value null .
Yes, that’s why I don’t get why it generates Typescript declaration with arrays [] | [t] instead of t | null
I also think there’s a better approach for these bindings, but I haven’t done a formal proposal on them yet. Optional arguments are the least JavaScriptey design of them all now, though
Yeah, it’s better to return T | undefined instead of T | null, because the JavaScript null can also represent the Motoko (), so if you had to return ?() in Motoko, that would map to null | null in JS, which wouldn’t work.
Do you know if and when the TS types for Optional will ever be changed to be T | undefined by default when dfx build is run? Also, is there an easy way for devs to override that locally until it’s officially changed?
I’m curious why it wasn’t done like that in the beginning.