tsgen

package
v0.85.0-pre.8 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StringLiteralUnion

func StringLiteralUnion(values ...string) string

StringLiteralUnion produces a TypeScript string literal union type, e.g. "active" | "inactive" | "pending".

func Union

func Union(types ...string) string

Union produces a TypeScript union type, e.g. SuccessResponse | ErrorResponse.

Types

type GoTypeRegistry

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

GoTypeRegistry collects Go types and resolves them into TypeScript definitions.

func (*GoTypeRegistry) Add

func (r *GoTypeRegistry) Add(input_types ...*GoTypeSrc)

Add registers one or more Go types for TypeScript generation.

func (*GoTypeRegistry) ResolveTypes

func (r *GoTypeRegistry) ResolveTypes() (ResolvedTSTypes, error)

ResolveTypes walks all registered types, deduplicates, resolves name collisions, and returns the final map of type definitions keyed by ID.

type GoTypeSrc

type GoTypeSrc struct {
	Instance      any    // Required
	RequestedName string // Optional
}

GoTypeSrc represents a Go type that needs a TypeScript definition.

func GoType

func GoType[T any](requested_name ...string) *GoTypeSrc

func (GoTypeSrc) ID

func (a GoTypeSrc) ID() ID

ID returns the deterministic ID for this type. This is the same key used in the map returned by Registry.ResolveTypes(). It can also be used as a TSTyper value (via string(id)) to create a reference to a system-managed type.

type ID

type ID string

ID is a deterministic, opaque identifier for a resolved type.

type ResolvedTSType

type ResolvedTSType struct {
	ID   ID
	Name string // Resolved, unique TS name (e.g. "UserResponse")
	Body string // The TS type body (e.g. "{ id: string; name: string }")
}

ResolvedTSType is a single resolved type definition.

type ResolvedTSTypes

type ResolvedTSTypes map[ID]ResolvedTSType

type TSDrafter

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

TSDrafter is a builder for producing TypeScript const, type, and enum declarations. It implements fmt.Stringer.

func (*TSDrafter) Const

func (d *TSDrafter) Const(name string, val any) *TSDrafter

func (*TSDrafter) Enum

func (d *TSDrafter) Enum(
	const_name, type_name string,
	val any,
) *TSDrafter

func (*TSDrafter) ExportConst

func (d *TSDrafter) ExportConst(name string, val any) *TSDrafter

func (*TSDrafter) ExportEnum

func (d *TSDrafter) ExportEnum(
	const_name, type_name string,
	val any,
) *TSDrafter

func (*TSDrafter) ExportType

func (d *TSDrafter) ExportType(name string, val string) *TSDrafter

func (*TSDrafter) Raw

func (d *TSDrafter) Raw(content string) *TSDrafter

func (*TSDrafter) String

func (d *TSDrafter) String() string

func (*TSDrafter) Type

func (d *TSDrafter) Type(name string, val string) *TSDrafter

type TSTyper

type TSTyper interface {
	TSType() map[string]string
}

TSTyper lets a struct override specific field types or add extra fields. Keys are Go field names. Values are literal TS type strings, or sentinel IDs obtained from Type.ID() for referencing system-managed types.

type TSTyperRaw

type TSTyperRaw interface {
	TSType() string
}

TSTyperRaw lets a struct bypass reflection entirely. The returned string becomes the whole TS type body verbatim.

Jump to

Keyboard shortcuts

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