Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hand made Option type #147

Open
czocher opened this issue Oct 19, 2023 · 0 comments
Open

Hand made Option type #147

czocher opened this issue Oct 19, 2023 · 0 comments

Comments

@czocher
Copy link
Contributor

czocher commented Oct 19, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant