tstypes

package
v3.116.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Helper code to assist emitting correctly minimally parenthesized TypeScript type literals.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TypeLiteral

func TypeLiteral(ast TypeAst) string

Produces a TypeScript type literal for the type, with minimally inserted parentheses.

Types

type TypeAst

type TypeAst interface {
	// contains filtered or unexported methods
}

Supported types include type identifiers, arrays `T[]`, unions `A|B`, and maps with string keys.

func Array

func Array(t TypeAst) TypeAst

Builds a `T[]` type from a `T` type.

func Identifier

func Identifier(id string) TypeAst

Builds a type identifier (possibly qualified such as "my.module.MyType") or a primitive such as "boolean".

func Normalize

func Normalize(ast TypeAst) TypeAst

Normalizes by unnesting unions `A | (B | C) => A | B | C`.

func StringMap

func StringMap(t TypeAst) TypeAst

Builds a `{[key: string]: T}` type from a `T` type.

func Union

func Union(t ...TypeAst) TypeAst

Builds a union `A | B | C` type.

Jump to

Keyboard shortcuts

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