typescript

package
v0.2.0 Latest Latest
Warning

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

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

README

TypeScript and TSX builders

The go.osspkg.com/gogen/typescript package builds TypeScript and TSX source from Go. It provides package-level constructors and chainable *Tokens methods, backed by the shared gogen token renderer.

go get go.osspkg.com/gogen/typescript

Build and render TypeScript

Compose declarations from builders, then render the token sequence to an io.Writer:

package main

import (
	"bytes"
	"fmt"

	ts "go.osspkg.com/gogen/typescript"
)

func main() {
	userType := ts.Export().Type().ID("User").Op("=").Block(
		ts.ID("id").Colon().String().Semicolon(),
		ts.ID("name").Colon().String().Semicolon(),
	).Semicolon()
	file := ts.Import("node:fs/promises", ts.ImportNames(ts.ID("readFile"))).Line().Join(userType)

	var source bytes.Buffer
	if err := ts.Render(&source, file); err != nil {
		panic(err)
	}
	fmt.Print(source.String())
}

Output:

import { readFile } from "node:fs/promises";
export type User = {
	id: string;
	name: string;
};

Tokens.Render(w) and typescript.Render(w, token) produce readable token output without formatting, compiling, or type-checking it. Block creates explicit indented layout; nested token sequences do not imply line breaks. Use .ts when the generated file has no JSX.

Build TSX

TSX nodes are structural tokens. The API does not depend on React or another framework. Use JSXText for literal text and JSXExpr for expressions; use the attribute builder that matches the value kind:

package main

import (
	"bytes"
	"fmt"

	"go.osspkg.com/gogen/types"
	ts "go.osspkg.com/gogen/typescript"
)

func main() {
	node := ts.JSXElement(
		ts.ID("button"),
		[]types.Token{
			ts.JSXAttribute("type", "button"),
			ts.JSXAttributeExpr("disabled", ts.ID("isDisabled")),
			ts.JSXSpreadAttribute(ts.ID("props")),
			ts.JSXBooleanAttribute("autoFocus"),
		},
		ts.JSXText("Save "),
		ts.JSXExpr(ts.ID("label")),
	)
	var source bytes.Buffer
	if err := ts.Render(&source, node); err != nil {
		panic(err)
	}
	fmt.Print(source.String())
}

The rendered node is:

<button type="button" disabled={isDisabled} {...props} autoFocus>Save {label}</button>

Use JSXFragment(children...) for a fragment. An element with no children is rendered as self-closing JSX. Text and quoted attribute values are escaped for JSX; expression tokens are rendered inside braces. Write generated code containing JSX to a .tsx file. This package does not run a formatter; invoke TypeScript or Prettier separately when needed.

Builder reference

Builders are available both as package-level functions and as chainable *Tokens methods, except where noted. TemplateText and TemplateExpr return tokens to pass to Template.

Area Builders Notes
Modules Import, ImportType, ImportNames, ImportNamespace, Export, ExportDefault, ExportNames, ExportFrom, From From is fluent-only. Supports side-effect, default, named, namespace, type-only, and re-export declarations. Use ID(name).As().ID(alias) for aliases.
Declarations Const, Let, Var, Function, Type, Interface, Class, Namespace, Async, Await, Return, Throw, Extends, Implements, New, This Compose declarations and common statement keywords. Use Bracket for parameters, Colon for annotations, and Block for bodies.
Class modifiers Public, Private, Protected, Static, Readonly, Abstract, Override, Constructor Compose common class members and constructors.
Control flow If, Else, ElseIf, For, ForOf, ForIn, While, Do, Switch, Case, Default, Break, Continue, Try, Catch, Finally, Of ForOf and ForIn create loops with a const binding.
Expressions ID, Pkg, Raw, Text, Op, Call, Bracket, List, Index, TypeArgs, Selector, OptionalChain, NewCall, KeyValue, Spread, Arrow, As, Optional, NonNull Text creates an escaped string literal; Raw inserts caller-provided source verbatim.
Punctuation Comma, Colon, Semicolon Append the corresponding syntax separators.
Values and types ObjectLiteral, ArrayLiteral, Template, TemplateText, TemplateExpr, Any, Unknown, Never, Void, String, Number, Boolean, BigInt, Symbol, ObjectType, Null, Undefined, True, False, ArrayType, RecordType, MapType, SetType, PromiseType, Union, Intersection Compose object/array values, template strings, primitive and utility types, and unions or intersections.
TSX JSXElement, JSXFragment, JSXAttribute, JSXAttributeExpr, JSXBooleanAttribute, JSXSpreadAttribute, JSXText, JSXExpr Build elements, fragments, attributes, text nodes, and expression children.
Layout and output Block, Comment, Line, Join, Render, Unwrap Set explicit layout, combine token sequences, render source, or access the underlying token slice.

Rendering errors and raw source

Rendering returns errors from the destination writer and from invalid builder input. ID validates identifier syntax, and Op rejects operators outside the adapter's supported set. TSX rendering rejects invalid attribute names, nil tags, nil expressions, and nil children. An element with no children is valid and self-closing.

Raw(source) writes the supplied source verbatim. It does not parse or validate it, so keep raw input under the caller's control. Text(value) emits an escaped JavaScript string literal; JSXText(value) and JSXAttribute(name, value) escape literal values for their JSX contexts.

For the repository overview and other language guides, see the root README, Go guide, and Python guide. The package's exported symbols are also documented on pkg.go.dev.

Documentation

Overview

Package typescript builds TypeScript and TSX source from composable tokens. Package-level builders create token sequences and fluent methods append to them. Render writes readable token layout without formatting, compiling, or type-checking the output.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(w io.Writer, arg types.Token) error

Render writes arg to w without running a formatter or compiler.

Example
package main

import (
	"bytes"
	"fmt"

	ts "go.osspkg.com/gogen/typescript"
)

func main() {
	file := ts.ExportDefault(
		ts.Function().ID("Greeting").Bracket(
			ts.ID("name").Colon().String(),
		).Block(
			ts.Return().Text("Hello, ").Op("+").ID("name").Semicolon(),
		),
	)

	var source bytes.Buffer
	if err := ts.Render(&source, file); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Print(source.String())

}
Output:
export default function Greeting(name: string) {
	return "Hello, " + name;
}

func TemplateExpr

func TemplateExpr(expression types.Token) types.Token

TemplateExpr creates an interpolated template-string expression token.

func TemplateText

func TemplateText(value string) types.Token

TemplateText creates a token containing escaped template-string text.

Types

type Tokens

type Tokens []types.Token

Tokens is a chainable sequence of TypeScript or TSX tokens.

func Abstract

func Abstract() *Tokens

Abstract appends the abstract modifier.

func Any

func Any() *Tokens

Any appends the any type.

func ArrayLiteral

func ArrayLiteral(values ...types.Token) *Tokens

ArrayLiteral creates or appends an array literal.

func ArrayType

func ArrayType(element types.Token) *Tokens

ArrayType creates an array type from its element type.

func Arrow

func Arrow() *Tokens

Arrow appends the arrow-function operator.

func As

func As() *Tokens

As appends the as keyword for aliases or type assertions.

func Async

func Async() *Tokens

Async appends the async modifier.

func Await

func Await() *Tokens

Await appends the await keyword.

func BigInt

func BigInt() *Tokens

BigInt appends the bigint type.

func Block

func Block(args ...types.Token) *Tokens

Block creates or appends a brace-delimited block with indentation.

func Boolean

func Boolean() *Tokens

Boolean appends the boolean type.

func Bracket

func Bracket(args ...types.Token) *Tokens

Bracket creates or appends a parenthesized token list.

func Break

func Break() *Tokens

Break appends a break statement keyword.

func Call

func Call(args ...types.Token) *Tokens

Call creates or appends a parenthesized call argument list.

func Case

func Case() *Tokens

Case starts a case clause.

func Catch

func Catch() *Tokens

Catch starts a catch clause.

func Class

func Class() *Tokens

Class appends the class declaration keyword.

func Colon

func Colon() *Tokens

Colon appends a colon separator.

func Comma

func Comma() *Tokens

Comma appends a comma separator.

func Comment

func Comment(value string) *Tokens

Comment appends a TypeScript line comment.

func Const

func Const() *Tokens

Const appends the const declaration keyword.

func Constructor

func Constructor() *Tokens

Constructor appends the constructor keyword.

func Continue

func Continue() *Tokens

Continue appends a continue statement keyword.

func Default

func Default() *Tokens

Default starts a default clause.

func Do

func Do() *Tokens

Do starts a do-while loop.

func Else

func Else() *Tokens

Else appends an else branch.

func ElseIf

func ElseIf() *Tokens

ElseIf starts an else-if branch.

func Export

func Export() *Tokens

Export appends the export keyword.

func ExportDefault

func ExportDefault(declaration types.Token) *Tokens

ExportDefault creates a default export declaration.

func ExportFrom

func ExportFrom(module string, specifiers ...types.Token) *Tokens

ExportFrom creates a re-export declaration from a module.

func ExportNames

func ExportNames(specifiers ...types.Token) *Tokens

ExportNames creates a named export declaration.

func Extends

func Extends() *Tokens

Extends appends the extends keyword.

func False

func False() *Tokens

False appends the false literal.

func Finally

func Finally() *Tokens

Finally starts a finally clause.

func For

func For() *Tokens

For starts a for statement.

func ForIn

func ForIn(name string, object types.Token) *Tokens

ForIn creates a for-in loop with a const binding.

func ForOf

func ForOf(name string, iterable types.Token) *Tokens

ForOf creates a for-of loop with a const binding.

func Function

func Function() *Tokens

Function appends the function declaration keyword.

func ID

func ID(name string) *Tokens

ID appends a validated TypeScript identifier.

func If

func If() *Tokens

If starts an if statement.

func Implements

func Implements() *Tokens

Implements appends the implements keyword.

func Import

func Import(module string, clause ...types.Token) *Tokens

Import creates an import declaration from a module.

Example
package main

import (
	"bytes"
	"fmt"

	ts "go.osspkg.com/gogen/typescript"
)

func main() {
	userType := ts.Export().Type().ID("User").Op("=").Block(
		ts.ID("id").Colon().String().Semicolon(),
		ts.ID("name").Colon().String().Semicolon(),
	).Semicolon()
	file := ts.Import("node:fs/promises", ts.ImportNames(ts.ID("readFile"))).Line().Join(userType)

	var source bytes.Buffer
	if err := ts.Render(&source, file); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Print(source.String())

}
Output:
import { readFile } from "node:fs/promises";
export type User = {
	id: string;
	name: string;
};

func ImportNames

func ImportNames(specifiers ...types.Token) *Tokens

ImportNames creates a named import or export specifier list.

func ImportNamespace

func ImportNamespace(alias, module string) *Tokens

ImportNamespace creates a namespace import declaration.

func ImportType

func ImportType(module string, clause ...types.Token) *Tokens

ImportType creates a type-only import declaration.

func Index

func Index(index types.Token) *Tokens

Index appends an indexed access expression.

func Interface

func Interface() *Tokens

Interface appends the interface declaration keyword.

func Intersection

func Intersection(types ...types.Token) *Tokens

Intersection creates an intersection type from its constituent types.

func JSXAttribute

func JSXAttribute(name, value string) *Tokens

JSXAttribute creates a quoted and escaped TSX string attribute.

Example
package main

import (
	"bytes"
	"fmt"

	"go.osspkg.com/gogen/types"
	ts "go.osspkg.com/gogen/typescript"
)

func main() {
	node := ts.JSXElement(
		ts.ID("button"),
		[]types.Token{
			ts.JSXAttribute("type", "button"),
			ts.JSXAttributeExpr("disabled", ts.ID("isDisabled")),
			ts.JSXSpreadAttribute(ts.ID("props")),
			ts.JSXBooleanAttribute("autoFocus"),
		},
		ts.JSXText("Save "),
		ts.JSXExpr(ts.ID("label")),
	)

	var source bytes.Buffer
	if err := ts.Render(&source, node); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Print(source.String())

}
Output:
<button type="button" disabled={isDisabled} {...props} autoFocus>Save {label}</button>

func JSXAttributeExpr

func JSXAttributeExpr(name string, expression types.Token) *Tokens

JSXAttributeExpr creates a TSX attribute containing an expression.

func JSXBooleanAttribute

func JSXBooleanAttribute(name string) *Tokens

JSXBooleanAttribute creates a valueless TSX boolean attribute.

func JSXElement

func JSXElement(tag types.Token, attributes []types.Token, children ...types.Token) *Tokens

JSXElement creates a structural TSX element with attributes and children.

Example
package main

import (
	"bytes"
	"fmt"

	"go.osspkg.com/gogen/types"
	ts "go.osspkg.com/gogen/typescript"
)

func main() {
	component := ts.ExportDefault(
		ts.Function().ID("Greeting").Bracket(
			ts.ID("name").Colon().String(),
		).Block(
			ts.Return().Join(ts.JSXElement(
				ts.ID("div"),
				[]types.Token{ts.JSXAttribute("className", "greeting")},
				ts.JSXText("Hello, "),
				ts.JSXExpr(ts.ID("name")),
			)),
		),
	)

	var source bytes.Buffer
	if err := ts.Render(&source, component); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Print(source.String())

}
Output:
export default function Greeting(name: string) {
	return <div className="greeting">Hello, {name}</div>
}

func JSXExpr

func JSXExpr(expression types.Token) *Tokens

JSXExpr creates a TSX expression child.

func JSXFragment

func JSXFragment(children ...types.Token) *Tokens

JSXFragment creates a TSX fragment containing child nodes.

func JSXSpreadAttribute

func JSXSpreadAttribute(expression types.Token) *Tokens

JSXSpreadAttribute creates a TSX spread attribute from an expression.

func JSXText

func JSXText(value string) *Tokens

JSXText creates an escaped TSX text node.

func KeyValue

func KeyValue(key, value types.Token) *Tokens

KeyValue creates a key-value member for an object or type literal.

func Let

func Let() *Tokens

Let appends the let declaration keyword.

func Line

func Line() *Tokens

Line appends an explicit line break.

func List

func List(args ...types.Token) *Tokens

List creates or appends a comma-separated token list without delimiters.

func MapType

func MapType(key, value types.Token) *Tokens

MapType creates a Map type from its key and value types.

func Namespace

func Namespace() *Tokens

Namespace appends the namespace declaration keyword.

func Never

func Never() *Tokens

Never appends the never type.

func New

func New() *Tokens

New appends the new keyword.

func NewCall

func NewCall(target types.Token, args ...types.Token) *Tokens

NewCall creates a constructor call expression.

func NonNull

func NonNull() *Tokens

NonNull appends a non-null assertion marker.

func Null

func Null() *Tokens

Null appends the null value.

func Number

func Number() *Tokens

Number appends the number type.

func ObjectLiteral

func ObjectLiteral(properties ...types.Token) *Tokens

ObjectLiteral creates or appends a multiline object literal.

func ObjectType

func ObjectType() *Tokens

ObjectType appends the object type.

func Of

func Of() *Tokens

Of appends the of keyword.

func Op

func Op(op string) *Tokens

Op appends a supported TypeScript operator.

func Optional

func Optional() *Tokens

Optional appends an optional-property marker.

func OptionalChain

func OptionalChain(name string) *Tokens

OptionalChain appends an optional property selector.

func Override

func Override() *Tokens

Override appends the override modifier.

func Pkg

func Pkg(module string) *Tokens

Pkg appends a module-style dotted prefix.

func Private

func Private() *Tokens

Private appends the private access modifier.

func PromiseType

func PromiseType(value types.Token) *Tokens

PromiseType creates a Promise type from its resolved value type.

func Protected

func Protected() *Tokens

Protected appends the protected access modifier.

func Public

func Public() *Tokens

Public appends the public access modifier.

func Raw

func Raw(source string) *Tokens

Raw appends source text verbatim.

func Readonly

func Readonly() *Tokens

Readonly appends the readonly modifier.

func RecordType

func RecordType(key, value types.Token) *Tokens

RecordType creates a Record type from its key and value types.

func Return

func Return() *Tokens

Return appends the return statement keyword.

func Selector

func Selector(name string) *Tokens

Selector appends a property selector.

func Semicolon

func Semicolon() *Tokens

Semicolon appends a statement terminator.

func SetType

func SetType(value types.Token) *Tokens

SetType creates a Set type from its element type.

func Spread

func Spread() *Tokens

Spread appends the spread operator.

func Static

func Static() *Tokens

Static appends the static modifier.

func String

func String() *Tokens

String appends the string type.

func Switch

func Switch() *Tokens

Switch starts a switch statement.

func Symbol

func Symbol() *Tokens

Symbol appends the symbol type.

func Template

func Template(parts ...types.Token) *Tokens

Template creates or appends a template string from text and expressions.

func Text

func Text(value string) *Tokens

Text appends a quoted and escaped JavaScript string literal.

func This

func This() *Tokens

This appends the this keyword.

func Throw

func Throw() *Tokens

Throw appends the throw statement keyword.

func True

func True() *Tokens

True appends the true literal.

func Try

func Try() *Tokens

Try starts a try statement.

func Type

func Type() *Tokens

Type appends the type-alias declaration keyword.

func TypeArgs

func TypeArgs(args ...types.Token) *Tokens

TypeArgs creates or appends generic type arguments.

func Undefined

func Undefined() *Tokens

Undefined appends the undefined value.

func Union

func Union(types ...types.Token) *Tokens

Union creates a union type from its alternatives.

func Unknown

func Unknown() *Tokens

Unknown appends the unknown type.

func Var

func Var() *Tokens

Var appends the var declaration keyword.

func Void

func Void() *Tokens

Void appends the void type.

func While

func While() *Tokens

While starts a while loop.

func (*Tokens) Abstract

func (v *Tokens) Abstract() *Tokens

Abstract appends the abstract modifier.

func (*Tokens) Any

func (v *Tokens) Any() *Tokens

Any appends the any type.

func (*Tokens) ArrayLiteral

func (v *Tokens) ArrayLiteral(values ...types.Token) *Tokens

ArrayLiteral creates or appends an array literal.

func (*Tokens) ArrayType

func (v *Tokens) ArrayType(element types.Token) *Tokens

ArrayType creates an array type from its element type.

func (*Tokens) Arrow

func (v *Tokens) Arrow() *Tokens

Arrow appends the arrow-function operator.

func (*Tokens) As

func (v *Tokens) As() *Tokens

As appends the as keyword for aliases or type assertions.

func (*Tokens) Async

func (v *Tokens) Async() *Tokens

Async appends the async modifier.

func (*Tokens) Await

func (v *Tokens) Await() *Tokens

Await appends the await keyword.

func (*Tokens) BigInt

func (v *Tokens) BigInt() *Tokens

BigInt appends the bigint type.

func (*Tokens) Block

func (v *Tokens) Block(args ...types.Token) *Tokens

Block creates or appends a brace-delimited block with indentation.

func (*Tokens) Boolean

func (v *Tokens) Boolean() *Tokens

Boolean appends the boolean type.

func (*Tokens) Bracket

func (v *Tokens) Bracket(args ...types.Token) *Tokens

Bracket creates or appends a parenthesized token list.

func (*Tokens) Break

func (v *Tokens) Break() *Tokens

Break appends a break statement keyword.

func (*Tokens) Call

func (v *Tokens) Call(args ...types.Token) *Tokens

Call creates or appends a parenthesized call argument list.

func (*Tokens) Case

func (v *Tokens) Case() *Tokens

Case starts a case clause.

func (*Tokens) Catch

func (v *Tokens) Catch() *Tokens

Catch starts a catch clause.

func (*Tokens) Class

func (v *Tokens) Class() *Tokens

Class appends the class declaration keyword.

func (*Tokens) Colon

func (v *Tokens) Colon() *Tokens

Colon appends a colon separator.

func (*Tokens) Comma

func (v *Tokens) Comma() *Tokens

Comma appends a comma separator.

func (*Tokens) Comment

func (v *Tokens) Comment(value string) *Tokens

Comment appends a TypeScript line comment.

func (*Tokens) Const

func (v *Tokens) Const() *Tokens

Const appends the const declaration keyword.

func (*Tokens) Constructor

func (v *Tokens) Constructor() *Tokens

Constructor appends the constructor keyword.

func (*Tokens) Continue

func (v *Tokens) Continue() *Tokens

Continue appends a continue statement keyword.

func (*Tokens) Default

func (v *Tokens) Default() *Tokens

Default starts a default clause.

func (*Tokens) Do

func (v *Tokens) Do() *Tokens

Do starts a do-while loop.

func (*Tokens) Else

func (v *Tokens) Else() *Tokens

Else appends an else branch.

func (*Tokens) ElseIf

func (v *Tokens) ElseIf() *Tokens

ElseIf starts an else-if branch.

func (*Tokens) Export

func (v *Tokens) Export() *Tokens

Export appends the export keyword.

func (*Tokens) ExportDefault

func (v *Tokens) ExportDefault(declaration types.Token) *Tokens

ExportDefault creates a default export declaration.

func (*Tokens) ExportFrom

func (v *Tokens) ExportFrom(module string, specifiers ...types.Token) *Tokens

ExportFrom creates a re-export declaration from a module.

func (*Tokens) ExportNames

func (v *Tokens) ExportNames(specifiers ...types.Token) *Tokens

ExportNames creates a named export declaration.

func (*Tokens) Extends

func (v *Tokens) Extends() *Tokens

Extends appends the extends keyword.

func (*Tokens) False

func (v *Tokens) False() *Tokens

False appends the false literal.

func (*Tokens) Finally

func (v *Tokens) Finally() *Tokens

Finally starts a finally clause.

func (*Tokens) For

func (v *Tokens) For() *Tokens

For starts a for statement.

func (*Tokens) ForIn

func (v *Tokens) ForIn(name string, object types.Token) *Tokens

ForIn creates a for-in loop with a const binding.

func (*Tokens) ForOf

func (v *Tokens) ForOf(name string, iterable types.Token) *Tokens

ForOf creates a for-of loop with a const binding.

func (*Tokens) From

func (v *Tokens) From(module string) *Tokens

From appends a from clause with a quoted module path.

func (*Tokens) Function

func (v *Tokens) Function() *Tokens

Function appends the function declaration keyword.

func (*Tokens) ID

func (v *Tokens) ID(name string) *Tokens

ID appends a validated TypeScript identifier.

func (*Tokens) If

func (v *Tokens) If() *Tokens

If starts an if statement.

func (*Tokens) Implements

func (v *Tokens) Implements() *Tokens

Implements appends the implements keyword.

func (*Tokens) Import

func (v *Tokens) Import(module string, clause ...types.Token) *Tokens

Import creates an import declaration from a module.

func (*Tokens) ImportNames

func (v *Tokens) ImportNames(specifiers ...types.Token) *Tokens

ImportNames creates a named import or export specifier list.

func (*Tokens) ImportNamespace

func (v *Tokens) ImportNamespace(alias, module string) *Tokens

ImportNamespace creates a namespace import declaration.

func (*Tokens) ImportType

func (v *Tokens) ImportType(module string, clause ...types.Token) *Tokens

ImportType creates a type-only import declaration.

func (*Tokens) Index

func (v *Tokens) Index(index types.Token) *Tokens

Index appends an indexed access expression.

func (*Tokens) Interface

func (v *Tokens) Interface() *Tokens

Interface appends the interface declaration keyword.

func (*Tokens) Intersection

func (v *Tokens) Intersection(types ...types.Token) *Tokens

Intersection creates an intersection type from its constituent types.

func (*Tokens) JSXAttribute

func (v *Tokens) JSXAttribute(name, value string) *Tokens

JSXAttribute creates a quoted and escaped TSX string attribute.

func (*Tokens) JSXAttributeExpr

func (v *Tokens) JSXAttributeExpr(name string, expression types.Token) *Tokens

JSXAttributeExpr creates a TSX attribute containing an expression.

func (*Tokens) JSXBooleanAttribute

func (v *Tokens) JSXBooleanAttribute(name string) *Tokens

JSXBooleanAttribute creates a valueless TSX boolean attribute.

func (*Tokens) JSXElement

func (v *Tokens) JSXElement(tag types.Token, attributes []types.Token, children ...types.Token) *Tokens

JSXElement creates a structural TSX element with attributes and children.

func (*Tokens) JSXExpr

func (v *Tokens) JSXExpr(expression types.Token) *Tokens

JSXExpr creates a TSX expression child.

func (*Tokens) JSXFragment

func (v *Tokens) JSXFragment(children ...types.Token) *Tokens

JSXFragment creates a TSX fragment containing child nodes.

func (*Tokens) JSXSpreadAttribute

func (v *Tokens) JSXSpreadAttribute(expression types.Token) *Tokens

JSXSpreadAttribute creates a TSX spread attribute from an expression.

func (*Tokens) JSXText

func (v *Tokens) JSXText(value string) *Tokens

JSXText creates an escaped TSX text node.

func (*Tokens) Join

func (v *Tokens) Join(args ...types.Token) *Tokens

Join appends tokens to the sequence and returns it.

func (*Tokens) KeyValue

func (v *Tokens) KeyValue(key, value types.Token) *Tokens

KeyValue creates a key-value member for an object or type literal.

func (*Tokens) Let

func (v *Tokens) Let() *Tokens

Let appends the let declaration keyword.

func (*Tokens) Line

func (v *Tokens) Line() *Tokens

Line appends an explicit line break.

func (*Tokens) List

func (v *Tokens) List(args ...types.Token) *Tokens

List creates or appends a comma-separated token list without delimiters.

func (*Tokens) MapType

func (v *Tokens) MapType(key, value types.Token) *Tokens

MapType creates a Map type from its key and value types.

func (*Tokens) Namespace

func (v *Tokens) Namespace() *Tokens

Namespace appends the namespace declaration keyword.

func (*Tokens) Never

func (v *Tokens) Never() *Tokens

Never appends the never type.

func (*Tokens) New

func (v *Tokens) New() *Tokens

New appends the new keyword.

func (*Tokens) NewCall

func (v *Tokens) NewCall(target types.Token, args ...types.Token) *Tokens

NewCall creates a constructor call expression.

func (*Tokens) NonNull

func (v *Tokens) NonNull() *Tokens

NonNull appends a non-null assertion marker.

func (*Tokens) Null

func (v *Tokens) Null() *Tokens

Null appends the null value.

func (*Tokens) Number

func (v *Tokens) Number() *Tokens

Number appends the number type.

func (*Tokens) ObjectLiteral

func (v *Tokens) ObjectLiteral(properties ...types.Token) *Tokens

ObjectLiteral creates or appends a multiline object literal.

func (*Tokens) ObjectType

func (v *Tokens) ObjectType() *Tokens

ObjectType appends the object type.

func (*Tokens) Of

func (v *Tokens) Of() *Tokens

Of appends the of keyword.

func (*Tokens) Op

func (v *Tokens) Op(op string) *Tokens

Op appends a supported TypeScript operator.

func (*Tokens) Optional

func (v *Tokens) Optional() *Tokens

Optional appends an optional-property marker.

func (*Tokens) OptionalChain

func (v *Tokens) OptionalChain(name string) *Tokens

OptionalChain appends an optional property selector.

func (*Tokens) Override

func (v *Tokens) Override() *Tokens

Override appends the override modifier.

func (*Tokens) Pkg

func (v *Tokens) Pkg(module string) *Tokens

Pkg appends a module-style dotted prefix.

func (*Tokens) Private

func (v *Tokens) Private() *Tokens

Private appends the private access modifier.

func (*Tokens) PromiseType

func (v *Tokens) PromiseType(value types.Token) *Tokens

PromiseType creates a Promise type from its resolved value type.

func (*Tokens) Protected

func (v *Tokens) Protected() *Tokens

Protected appends the protected access modifier.

func (*Tokens) Public

func (v *Tokens) Public() *Tokens

Public appends the public access modifier.

func (*Tokens) Raw

func (v *Tokens) Raw(source string) *Tokens

Raw appends source text verbatim.

func (*Tokens) Readonly

func (v *Tokens) Readonly() *Tokens

Readonly appends the readonly modifier.

func (*Tokens) RecordType

func (v *Tokens) RecordType(key, value types.Token) *Tokens

RecordType creates a Record type from its key and value types.

func (*Tokens) Render

func (v *Tokens) Render(w io.Writer) error

Render writes the token sequence to w without formatting it.

func (*Tokens) Return

func (v *Tokens) Return() *Tokens

Return appends the return statement keyword.

func (*Tokens) Selector

func (v *Tokens) Selector(name string) *Tokens

Selector appends a property selector.

func (*Tokens) Semicolon

func (v *Tokens) Semicolon() *Tokens

Semicolon appends a statement terminator.

func (*Tokens) SetType

func (v *Tokens) SetType(value types.Token) *Tokens

SetType creates a Set type from its element type.

func (*Tokens) Spread

func (v *Tokens) Spread() *Tokens

Spread appends the spread operator.

func (*Tokens) Static

func (v *Tokens) Static() *Tokens

Static appends the static modifier.

func (*Tokens) String

func (v *Tokens) String() *Tokens

String appends the string type.

func (*Tokens) Switch

func (v *Tokens) Switch() *Tokens

Switch starts a switch statement.

func (*Tokens) Symbol

func (v *Tokens) Symbol() *Tokens

Symbol appends the symbol type.

func (*Tokens) Template

func (v *Tokens) Template(parts ...types.Token) *Tokens

Template creates or appends a template string from text and expressions.

func (*Tokens) Text

func (v *Tokens) Text(value string) *Tokens

Text appends a quoted and escaped JavaScript string literal.

func (*Tokens) This

func (v *Tokens) This() *Tokens

This appends the this keyword.

func (*Tokens) Throw

func (v *Tokens) Throw() *Tokens

Throw appends the throw statement keyword.

func (*Tokens) True

func (v *Tokens) True() *Tokens

True appends the true literal.

func (*Tokens) Try

func (v *Tokens) Try() *Tokens

Try starts a try statement.

func (*Tokens) Type

func (v *Tokens) Type() *Tokens

Type appends the type-alias declaration keyword.

func (*Tokens) TypeArgs

func (v *Tokens) TypeArgs(args ...types.Token) *Tokens

TypeArgs creates or appends generic type arguments.

func (*Tokens) Undefined

func (v *Tokens) Undefined() *Tokens

Undefined appends the undefined value.

func (*Tokens) Union

func (v *Tokens) Union(types ...types.Token) *Tokens

Union creates a union type from its alternatives.

func (*Tokens) Unknown

func (v *Tokens) Unknown() *Tokens

Unknown appends the unknown type.

func (*Tokens) Unwrap

func (v *Tokens) Unwrap() []types.Token

Unwrap returns the underlying token slice without copying it.

func (*Tokens) Var

func (v *Tokens) Var() *Tokens

Var appends the var declaration keyword.

func (*Tokens) Void

func (v *Tokens) Void() *Tokens

Void appends the void type.

func (*Tokens) While

func (v *Tokens) While() *Tokens

While starts a while loop.

Jump to

Keyboard shortcuts

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