tkrajina / typescriptify-golang-structs

A Golang struct to TypeScript class/interface converter
Apache License 2.0
505 stars 87 forks source link

Documentation comments #61

Closed harnyk closed 2 years ago

harnyk commented 2 years ago

I would like if the following struct:

// Header Item
type HeaderItem struct {
    //Header name
    Name  string `json:"name"`
    //Header value
    Value string `json:"value"`
}

would convert to the following interface

/**
 * Header Item
 */
interface HeaderItem {
   /**
    * Header name
    */
   name: string;

   /**
    * Header value
    */
   value: string;
}

Is it possible? Other option would be to have a special tag:

type HeaderItem struct {
    Name  string `json:"name" doc:"Header name"`
    Value string `json:"value" doc:"Header value"`
        _ struct{} `doc:"Header Item"`
}
gzuidhof commented 2 years ago

This library won't be able to support this as it's reflection based, you could consider using tygo instead.

tkrajina commented 2 years ago

You make it sound like "reflection based" is something very bad @gzuidhof :) "Parser based" solves some problems but introduces others (for example - how about inner structs or structs in multiple packages).

Anyway... Adding a tag for specifying typescript comments is simple to implement @harnyk .

tkrajina commented 2 years ago

@harnyk Added a way to specify field comments, see https://github.com/tkrajina/typescriptify-golang-structs#field-comments