Documentation ¶
Overview ¶
Package go2ts is a module for generating TypeScript definitions from Go structs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Go2TS ¶
type Go2TS struct {
// contains filtered or unexported fields
}
Go2TS writes TypeScript interface definitions for the given Go structs.
func (*Go2TS) Add ¶
Add a struct that needs a TypeScript definition.
Just a wrapper for AddWithName with an interfaceName of "".
See AddWithName.
func (*Go2TS) AddWithName ¶
AddWithName adds a struct that needs a TypeScript definition.
The value passed in must resolve to a struct, a reflect.Type, or a reflect.Value of a struct. That is, a string or number for v will cause AddWithName to return an error, but a pointer to a struct is fine.
The 'name' supplied will be the TypeScript interface name. If 'interfaceName' is "" then the struct name will be used. If the struct is anonymous it will be given a name of the form "AnonymousN".
The fields of the struct will be named following the convention for json serialization, including using the json tag if supplied.
Fields tagged with `json:",omitempty"` will have "| null" added to their type.
There is special handling of time.Time types to be TypeScript "string"s since they implement MarshalJSON, see https://pkg.go.dev/time?tab=doc#Time.MarshalJSON.