Documentation
¶
Overview ¶
Package jsrt provides runtime support for TypeScript-to-Go transpiled code.
Index ¶
- func GetField(v any, name string) any
- func GetFieldAs[T any](v any, name string) T
- func Index(v any, key any) any
- func Len(v any) int
- func Ptr[T any](v T) *T
- func SetIndex(v any, key any, val any)
- func Throw(v any)
- func ThrowError(msg string)
- func ThrowTypeError(msg string)
- func ToAnySlice[T any](s []T) []any
- func ToBool(v any) bool
- func TypeOf(v any) string
- type JSError
- type JSObject
- func (o *JSObject) Bool() bool
- func (o *JSObject) Call(args ...any) *JSObject
- func (o *JSObject) Float64() float64
- func (o *JSObject) Get(name string) *JSObject
- func (o *JSObject) Index(key any) *JSObject
- func (o *JSObject) Int() int
- func (o *JSObject) IsNil() bool
- func (o *JSObject) Len() int
- func (o *JSObject) Set(name string, value any)
- func (o *JSObject) String() string
- func (o *JSObject) Unwrap() any
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetField ¶
GetField accesses a field on an any-typed value by name, like JavaScript property access. Supports structs (by exported field name), maps (by original or exported key), and pointers. For maps, tries the original name first, then the exported (PascalCase) name. For structs, tries the exported name first, then the original name.
func GetFieldAs ¶
GetFieldAs is a typed version of GetField that returns a value of the specified type.
func Ptr ¶
func Ptr[T any](v T) *T
Ptr returns a pointer to the given value. Useful for passing literals to *T parameters.
func Throw ¶
func Throw(v any)
Throw panics with a JSError, simulating JavaScript's throw statement.
func ThrowTypeError ¶
func ThrowTypeError(msg string)
ThrowTypeError simulates throw new TypeError(msg).
Types ¶
type JSError ¶
JSError represents a JavaScript error thrown with throw statement.
func CatchValue ¶
CatchValue converts a recovered panic value into a *JSError.
type JSObject ¶
type JSObject struct {
V any // The underlying value
}
JSObject wraps an any value with JavaScript-like dynamic property access and method calls. Used by the transpiler as a fallback when TypeScript types cannot be statically mapped to Go types. When the TypeScript checker provides concrete type information (including narrowed types), the transpiler generates concrete Go types with type assertions instead.
func (*JSObject) Get ¶
Get accesses a property by name, returning a new JSObject. Supports structs (exported fields), maps (string keys), and *JSObject nesting.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package array provides JavaScript Array.prototype method equivalents using Go generics.
|
Package array provides JavaScript Array.prototype method equivalents using Go generics. |
|
compat
|
|
|
lodash
Package lodash provides Go adapters for commonly used lodash/lodash-es functions.
|
Package lodash provides Go adapters for commonly used lodash/lodash-es functions. |
|
uuid
Package uuid provides a Go adapter for the npm "uuid" package.
|
Package uuid provides a Go adapter for the npm "uuid" package. |
|
zod
Package zod provides a Go adapter for the npm "zod" schema validation library.
|
Package zod provides a Go adapter for the npm "zod" schema validation library. |
|
Package console provides console.log/error/warn for transpiled TypeScript code.
|
Package console provides console.log/error/warn for transpiled TypeScript code. |
|
Package fetch provides the fetch() API for transpiled TypeScript code.
|
Package fetch provides the fetch() API for transpiled TypeScript code. |
|
node
|
|
|
crypto
Package crypto provides Node.js crypto module equivalents for transpiled TypeScript code.
|
Package crypto provides Node.js crypto module equivalents for transpiled TypeScript code. |
|
fs
Package fs provides Node.js fs module equivalents for transpiled TypeScript code.
|
Package fs provides Node.js fs module equivalents for transpiled TypeScript code. |
|
http
Package http provides Node.js http module equivalents for transpiled TypeScript code.
|
Package http provides Node.js http module equivalents for transpiled TypeScript code. |
|
path
Package path provides Node.js path module equivalents for transpiled TypeScript code.
|
Package path provides Node.js path module equivalents for transpiled TypeScript code. |
|
Package promise provides a Promise[T] type for transpiled async/await TypeScript code.
|
Package promise provides a Promise[T] type for transpiled async/await TypeScript code. |
|
Package web provides Go struct definitions for Web API types used by transpiled TypeScript code.
|
Package web provides Go struct definitions for Web API types used by transpiled TypeScript code. |