tsgen

package
v0.0.62 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2024 License: BSD-3-Clause Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateTSContent added in v0.0.50

func GenerateTSContent(opts Opts) (string, error)

GenerateTSContent generates TypeScript content from the given options

func GenerateTSToFile added in v0.0.50

func GenerateTSToFile(opts Opts) error

GenerateTSToFile generates a TypeScript file from the provided Opts.

Types

type AdHocType added in v0.0.50

type AdHocType struct {
	// Instance of the struct to generate TypeScript for
	Struct any

	// Name is required only if struct is anonymous, otherwise optional override
	TSTypeName string
}

type ArbitraryProperty added in v0.0.50

type ArbitraryProperty struct {
	Name  string
	Value any
}

Anything you'd like to add to a TypeScript type object, other than the phantom types. Value must be JSON-serializable.

type Item added in v0.0.50

type Item struct {
	ArbitraryProperties []ArbitraryProperty
	PhantomTypes        []PhantomType
}

Item represents a TypeScript object type with arbitrary properties and phantom types. It will be added to a constant array in the generated TypeScript file with the name assigned to ItemsArrayVarName in Opts.

type Opts

type Opts struct {
	// Path, including filename, where the resulting TypeScript file will be written
	OutPath           string
	Items             []Item
	AdHocTypes        []AdHocType
	ExtraTSCode       string
	ItemsArrayVarName string // Defaults to "tsgenItems"
	ExportItemsArray  bool
}

type PhantomType added in v0.0.50

type PhantomType struct {
	PropertyName string
	TSTypeName   string
	TypeInstance any
}

Jump to

Keyboard shortcuts

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