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

How to handle nullable reference types #52

Open
thebuilder opened this issue Apr 16, 2021 · 1 comment
Open

How to handle nullable reference types #52

thebuilder opened this issue Apr 16, 2021 · 1 comment

Comments

@thebuilder
Copy link

Hey, really cool tool. Tried it on on set of c# code models we have to compare it to our TypeScript models.
This does reveal one issue - some types like string could be nullable by default.
https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references

An example would be the following conversion:

public class LinkViewModel {
  public Href { get; set; }
  public string Label { get; set; }
  public string Title { get; set; }
  public LinkTargetTypes? Target { get; set; }
}
export interface LinkViewModel {
  href: string;
  label: string;
  title: string;
  target?: LinkTargetTypes;
}

The problem is, these values could actually be null, or undefined (depending on how you ship the data).
TypeScript would not throw an error if you try to use a string method on on any of the string values.

Would it make sense to be able to control how reference types are handled?

@svenheden
Copy link
Owner

Would it make sense to be able to control how reference types are handled?

Yeah I think that's a great idea. If you're up for it feel free to submit a PR for adding a setting like this.

Thanks for the suggestion!

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

2 participants