-
Notifications
You must be signed in to change notification settings - Fork 132
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
Optional type #22
Comments
Hi @dodyg, could you please provide some more details about this? An example would be nice. |
How can I generate
|
If you want it on all properties, just add the question mark in the template like this: $Classes(*Models*)[
interface $Name { $Properties[
$Name?: $Type;]
}] Otherwise the problem is how to determine which properties should be decorated. One solution is to use attributes to mark optional properties in your c# classes e.g: ${
var IsOptional = (Property p) => p.Attributes.Any(a => a.Name == "Optional");
}
$Classes(*Models*)[
interface $Name { $Properties[
$Name$IsOptional[?]: $Type;]
}] public class Person
{
[Optional]
public string Name { get; set; }
public int Age { get; set; }
} |
This is exactly what I need. Thank you so much. I just created a dummy Optional attribute and tag the necessary properties with it
|
Is there anyway to generate typescript definition with optional type? This is especially important when trying to generate typescript interfaces automatically
The text was updated successfully, but these errors were encountered: