tsGen

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

tsGen

TsGen

  • Implementation notes:
    • unexported fields are ignored
    • nested structs are flattened and defined as separate interfaces
    • pointer types are represented as nullable types (e.g., Type | null)
    • function types are represented as 'Function'
    • interface, chan, complex types are represented as 'any'
    • invalid types are represented as 'unknown'
    • Anonymous nested struct are embedded into the parent struct
    • Anonymous field in struct are ignored
    • Support to struct tag to customize the field name and type with tskey and tstype tags

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GenericAny

type GenericAny any

GenericAny is an alias for any type, used for generic purposes.

type TsGen

type TsGen struct {
	// contains filtered or unexported fields
}

TsGen is responsible for converting Go structs to TypeScript interfaces.

func New

func New(options ...tsopts.TsGenOpts) *TsGen

New creates a new TsGen instance with the provided options.

func (*TsGen) AddType

func (t *TsGen) AddType(valType reflect.Type, opts ...tsopts.TsGenOpts) error

AddType registers a Go type for TypeScript interface generation.

func (*TsGen) AddTypeWithName

func (t *TsGen) AddTypeWithName(valType reflect.Type, headerName string, opts ...tsopts.TsGenOpts) error

AddTypeWithName registers a Go type with a custom TypeScript interface name.

func (*TsGen) AddValue

func (t *TsGen) AddValue(val any, opts ...tsopts.TsGenOpts) error

AddValue registers a Go value's type for TypeScript interface generation.

func (*TsGen) AddValueWithName

func (t *TsGen) AddValueWithName(val any, headerName string, opts ...tsopts.TsGenOpts) error

AddValueWithName registers a Go value's type with a custom TypeScript interface name.

func (*TsGen) GetRegisteredTypes

func (t *TsGen) GetRegisteredTypes() *orderedmap.OrderedMap[string, *tsInterface.TsInterface]

GetRegisteredTypes returns all registered TypeScript interfaces.

func (*TsGen) GetType

func (t *TsGen) GetType(field reflect.StructField, opts ...tsopts.TsGenOpts) string

GetType returns the TypeScript type string for a given Go struct field.

func (*TsGen) String

func (t *TsGen) String() string

String returns the generated TypeScript interfaces as a string.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL