Type Mapping#

How Go types map to TypeScript types.

Primitives#

Go TypeTypeScript Type
stringstring
boolboolean
int, int8, int16, int32, int64number
uint, uint8, uint16, uint32, uint64number
float32, float64number

Typed Arrays#

Numeric slices map to TypeScript typed arrays for efficient data transfer:

Go TypeTypeScript TypePerformance
[]byte, []uint8Uint8ArrayBulk copy (~10-100x faster)
[]int8Int8ArrayElement iteration
[]int16Int16ArrayElement iteration
[]uint16Uint16ArrayElement iteration
[]int32Int32ArrayElement iteration
[]uint32Uint32ArrayElement iteration
[]float32Float32ArrayElement iteration
[]float64Float64ArrayElement iteration

Note: Only []byte uses efficient bulk copy via js.CopyBytesToGo() and js.CopyBytesToJS(). Other numeric types use element-by-element iteration.

Collections#

Go TypeTypeScript Type
[]TT[]
map[string]T{ [key: string]: T }

Limitation: Only map[string]T is supported. Maps with non-string keys are not supported.

Structs#

Go structs become TypeScript interfaces. Field names use JSON tags if present:

type User struct {
    ID        int    `json:"id"`
    FirstName string `json:"firstName"`
    IsActive  bool   `json:"isActive"`
}
interface User {
    id: number;
    firstName: string;
    isActive: boolean;
}

Functions#

Return Types#

Go ReturnTypeScript Return (Worker)TypeScript Return (Sync)
TPromise<T>T
(T, error)Promise<T> (throws on error)T (throws on error)
errorPromise<void> (throws on error)void (throws on error)
(none)Promise<void>void

Callbacks#

Void callbacks (no return value) are supported:

Go CallbackTypeScript Callback
func()() => void
func(T)(arg0: T) => void
func(T, U)(arg0: T, arg1: U) => void

Not supported: Callbacks with return values like func(T) bool.

Special Cases#

interface#

Go interface{} becomes TypeScript any:

func GetValue() interface{} { ... }
// → getValue(): Promise<any>

Recommendation: Use concrete types whenever possible.

Pointers#

Pointers are automatically dereferenced:

func GetUser() *User { ... }
// → getUser(): Promise<User>

Unsupported Types#

The following Go types are not supported and will cause validation errors:

  • Channels (chan T)
  • Interfaces (except error)
  • External package types (except standard library)
  • Function types as return values
  • Maps with non-string keys