-
Notifications
You must be signed in to change notification settings - Fork 117
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
Implement #[ts(optional = nullable)]
#213
Conversation
Closes #112 |
@escritorio-gustavo would love to hear what you think about this! |
This is awesome! I thought there would be a separate |
Quick question, is the #[derive(default)]
pub struct Nullable(pub bool);
#[derive(Default)]
pub struct FieldAttr {
pub type_override: Option<String>,
pub type_override: Option<String>,
pub rename: Option<String>,
pub rename: Option<String>,
pub inline: bool,
pub inline: bool,
pub skip: bool,
pub skip: bool,
pub optional: bool,
pub optional: Option<Nullable>,
pub flatten: bool,
pub flatten: bool,
}
let (ty, optional_annotation) = match optional {
Some(Nullable(nullable) => {
let inner_type = extract_option_argument(&field.ty)?; // inner type of the optional
match nullable {
true => (&field.ty, "?"), // if it's nullable, we keep the original type
false => (inner_type, "?"), // if not, we use the Option's inner type
}
},
None => (&field.ty, "")
}; This is just an idea though, I'm totally fine with merging this as is |
Sure, that'd work as well. I tried a couple of options, and the one i ended up with felt the least ugly to me. |
I don't think there's a need for that, I was just curious |
This PR implements
#[ts(optional = nullable)]
, as discussed in #112.#[ts(optional)] Option<T>
still generatest?: T
, while#[ts(optional = nullable)]
generatest?: T | null
.I plan on following this up at some point with support for the serde attributes outlined in #112.