typeshare
typeshare copied to clipboard
Hand made Option type
We currently support Option<T> which can be represented as undefined or null in TypeScript. We also support Option<Option<T>> which lets one represent a field that can either be null or undefined (i.e. double optional pattern https://docs.rs/serde_with/latest/serde_with/rust/double_option/).
I'm wondering if there's any way we can create our own representation of double optional as:
enum Maybe<T> {
Null,
Undefined,
Value(T)
}
Such that it will have the following TypeScript representation:
struct Something {
field: Maybe<u32>,
}
interface Something {
field?: number | null;
}
Without using Option<Option<T>>. Is this possible?