Skip to content

output for pointers are always treated as omitempty #60

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

Open
sua-dawn opened this issue Jun 15, 2022 · 0 comments
Open

output for pointers are always treated as omitempty #60

sua-dawn opened this issue Jun 15, 2022 · 0 comments

Comments

@sua-dawn
Copy link

sua-dawn commented Jun 15, 2022

Disclaimer: The following has only been tested using WithInterface(true)- as we're only using interfaces.

Pointers behave as if ,omitempty is applied to the field tag.

This example:

type MyDTO struct {
  Example *float64 `json:"example"`
}

Outputs the following interface:

export interface MyDTO {
  example?: number;
}

This would be correct if the field tag was appended with ,omitempty, like so:

type MyDTO struct {
  Example *float64 `json:"example,omitempty"`
}

But without ,omitempty, the output should be:

export interface MyDTO {
  example: number | null;
}

Are there anyway to achieve this?

Also if I've misunderstood anything (I'm very new to GO), I'd like to apologize in advance 😬

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