Skip to content

Feature Request: allow non-pointer Go types on optional fields in TS #1348

@chaofz

Description

@chaofz

Hi,

Thanks for making this awesome tool! I have a feature request for the conversion from TS to Go. I wonder if it makes sense to add an option not to convert TS optional fields to Go pointer types.
I make this request because Go already treats all struct fields optional and drops empty with omitempty tag in JSON serialization.

For example
TS:

class Contact {
  firstName: string;
  lastName?: string;
}

Current state on converting to Go:

type Contact struct {
	FirstName string       `json:"firstName"`         
	LastName *string       `json:"lastName,omitempty"`
}

Proposed change:

type Contact struct {
	FirstName string      `json:"firstName"`         
	LastName string       `json:"lastName,omitempty"`
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions