Skip to content

output for pointers are always treated as omitempty #60

@sua-dawn

Description

@sua-dawn

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 😬

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions