Skip to content

Targo Cheatsheet

Targo uses TypeScript syntax, but its semantics are Go-first. Treat it as a Go language with a TypeScript-shaped surface, not as JavaScript with a different compiler.

Mental Model

  • src/ is the source of truth.
  • dist/ and tsconfig.targo.json are generated artifacts.
  • types/ and vendored .targo/ trees are generated declaration output when those workflows are used.
  • Validate against current Targo behavior, not against plain TypeScript expectations.
  • If a construct feels "valid TypeScript but not very Go-like", treat it as suspicious until verified.

Support Matrix

Core Types

FeatureStatusNotes
numberSupportedMaps to float64
Explicit Go numeric typesSupportedint, int64, uint32, float64, etc. Prefer at API boundaries
boolSupportedConditions must be explicitly bool
stringSupported.length follows Go len (byte length)
byte / runeSupportedGo character types
bigintSupportedMaps to *big.Int with immutability semantics
null / undefinedSupportedPart of Targo's nullable model
?. / ??SupportedOptional chaining and nullish coalescing

Structs and Types

FeatureStatusNotes
classSupportedGo struct with reference semantics
constructorSupportedSubject to checker restrictions
Inheritance via extendsNot supportedPrefer composition
interfaceSupportedGo-style contracts
GoInterfaceSupportedMarker for Go interface boundaries
Embedding<{ ... }>()SupportedStruct embedding pattern
DefinedType<...>()SupportedGo defined types
#private fieldsSupportedUse this form
private / protected keywordsNot supportedUse #field instead
Struct tagsSupportedVia @json / @tag JSDoc on fields

Collections

FeatureStatusNotes
slice<T>SupportedGo-native dynamic collection
Array<T> / T[]SupportedRuntime-backed collection with JS-style methods
map<K, V>SupportedGo map semantics
Map<K, V>SupportedRuntime-backed ordered map with JS-style methods
Set<T>SupportedRuntime-backed ordered set
Fixed<T, N>SupportedFixed-size Go arrays
chan<T>SupportedChannel communication

Functions and Flow

FeatureStatusNotes
Tuples for multi-returnSupported[T, error | null] pattern
error | nullSupportedPreferred error model
panic() / recover()SupportedUse sparingly
deferSupportedGo-style deferred execution
async/awaitNot supportedUse Go concurrency primitives
PromiseNot supportedNo JS async runtime
go(() => {})SupportedStarts goroutines
chan<T>SupportedChannel communication
switch (chan.$select)SupportedSelect-style coordination

Tooling and Interop

FeatureStatusNotes
Direct Go package importsSupportedRegenerate declarations after changes
targo initSupportedRefresh declarations and config-derived state
targo testSupportedUses Go's test runner
testing.T / testing.BSupportedStandard test and benchmark signatures
/** @go:* */ directivesSupportedJSDoc-based Go directives

Migration Quick Rules

  • Replace exception-driven APIs with explicit error returns.
  • Prefer slice<T> for Go-native code; use Array<T> when you explicitly need runtime collection methods.
  • Re-check string indexing assumptions when Unicode behavior matters.
  • Re-run npm run targo init after changing dependencies, imports, or Targo config.
  • Prefer the Go-shaped option over the JavaScript-shaped one.

When In Doubt

  • If you are reaching for Promise, extends, DOM APIs, or Node-only globals, stop and confirm the project actually supports that pattern.
  • Treat older Targo docs as suspicious unless they match current code and fixtures.
  • For agent workflows, start with .targo-docs/INDEX.md and then jump to the relevant topic file.

Runtime Declaration Files

Targo's type system and API surface are defined in .d.ts files. When you need to check exact signatures or whether an API exists, read these files directly:

FileLocationWhat it defines
lib.targo.d.ts.targo/lib.targo.d.tsCore types: slice, map, chan, Fixed, Ptr, Val, GoInterface, DefinedType, Embedding, numeric types, builtins (make, len, cap, append, copy, delete, close, go, defer, panic, recover, zero, ref, deref, min, max), generic constraints (comparable, Ordered, Signed, Unsigned, Integer, Float, Numeric)
lib.es.core.d.ts.targo/lib.es.core.d.tsES core skeletons: String, RegExp, Function (bind/call/apply), Symbol, Iterator, Map/Set/WeakMap/WeakSet constructor stubs
lib.es.d.tsnode_modules/@targo/runtime/lib.es.d.tsRuntime APIs: Array<T> methods, Array.of/from/make, String methods, RegExp, JSON (with [T, error] returns), Object, Map<K,V>/Set<T> full surface
lib.es.globals.d.tsnode_modules/@targo/runtime/lib.es.globals.d.tsGlobals: console.log/error (→ fmt), Math.* (→ math), NaN/Infinity/isNaN/isFinite
lib.embed.d.ts.targo/lib.embed.d.tsembed tagged template literal for @go:embed
lib.unsafe.d.ts.targo/lib.unsafe.d.tsunsafe.Pointer, Sizeof/Alignof/Offsetof, Slice/SliceData
~/.targo/pkg/std/goX.Y/*.d.tsGlobal cacheGo stdlib declarations: fmt, net/http, os, strings, time, errors, etc.