Global functions
Output, timers, parsers, type checks and the global constants.
Always available
No import needed. These names are in scope in every file.
print function
ts
function print(...args: Array<any>): voidWrite each argument to stdout on a single line, separated by spaces, followed by a newline. Values are stringified the same way as console.log. Unlike console.log, print has no level prefix and no per-stream routing — it is the lowest-level write helper.
dump function
ts
function dump(...args: Array<any>): voidDebug-print each expression with its source text as a label. The compiler rewrites dump(x, y.z) to __dump_labeled("x", x, "y.z", y.z), so the printed output reads x = 1, y.z = 42. Calling dump indirectly (e.g. through a variable binding) skips the rewrite and falls back to printing values without labels.
setTimeout function
ts
function setTimeout(handler: Function, delay?: int): intSchedule handler to run once after at least delay milliseconds. Omitted delay defaults to zero. Returns a numeric timer id usable with clearTimeout. A negative delay is clamped to zero. The runtime keeps the event loop alive until the timer fires or is cleared.
setInterval function
ts
function setInterval(handler: Function, delay: int): intSchedule handler to run repeatedly every delay milliseconds. Returns a numeric timer id usable with clearInterval. Delays below 1ms are clamped to 1ms. The first invocation occurs after one full interval, not immediately.
clearTimeout function
ts
function clearTimeout(id: int): voidCancel a pending setTimeout. Unknown ids are silently ignored.
clearInterval function
ts
function clearInterval(id: int): voidCancel a recurring setInterval. Unknown ids are silently ignored.
parseInt function
ts
function parseInt(text: string): intParse a base-10 integer from text. Leading whitespace is skipped and parsing stops at the first non-digit character. Returns 0 when no digits are found.
parseFloat function
ts
function parseFloat(text: string): float64Parse a floating-point number from text. Accepts decimal, exponential, and Infinity/NaN forms. Returns NaN when no numeric prefix is found.
parseUint function
ts
function parseUint(value: any, radix?: int): uintParse value as an unsigned 32-bit integer. Numeric inputs are truncated; string inputs are read in radix (default 10). Throws RangeError if the result is negative or exceeds UINT32_MAX.
parseBool function
ts
function parseBool(value: any): boolean | nullParse the boolean a piece of text denotes. Strings are normalised with lower(trim(value)) and matched against the word list: true/yes/on/enable/enabled/success/1 are true, false/no/off/disable/disabled/failure/0 and the empty string are false. A string outside the list returns null -- that is the only thing null means here. Non-strings fall back to plain truthiness, so parseBool(0) is false and parseBool({}) is true.
This is NOT Boolean(). Boolean(x) asks whether there is a value, so Boolean("false") is true. parseBool(x) asks what boolean the text denotes, so parseBool("false") is false. Both are correct; they answer different questions.
const debug: boolean = parseBool(Env.get("DEBUG")) ?? false;
isNaN function
ts
function isNaN(value: any): booleanTrue if value is the IEEE-754 NaN sentinel.
isFinite function
ts
function isFinite(value: any): booleanTrue if value is a finite number (not NaN, not ±Infinity).
isNumber function
ts
function isNumber(value: any): booleanTrue if value is any numeric type (int, uint, or float).
isString function
ts
function isString(value: any): booleanTrue if value is a string.
isBoolean function
ts
function isBoolean(value: any): booleanTrue if value is a boolean.
isInt function
ts
function isInt(value: any): booleanTrue if value is a 32-bit signed integer.
isUint function
ts
function isUint(value: any): booleanTrue if value is a 32-bit unsigned integer.
isNumeric function
ts
function isNumeric(value: any): booleanTrue if value is numeric.
isNull function
ts
function isNull(value: any): booleanTrue if value is null or undefined.
isArray function
ts
function isArray(value: any): booleanTrue if value is an array.
isObject function
ts
function isObject(value: any): booleanTrue if value is a plain object instance. Excludes arrays, maps, sets, and primitives.
isMap function
ts
function isMap(value: any): booleanTrue if value is a Map.
isSet function
ts
function isSet(value: any): booleanTrue if value is a Set.
thisType function
ts
function thisType(value: any): stringReturn the runtime type tag of value as a lowercase string. Possible values include "int", "uint", "float", "string", "boolean", "array", "object", "map", "set", "function", "null", and "undefined". More precise than the typeof operator, which collapses numeric variants.
declaredType function
ts
function declaredType(value: any): stringReturn the declared packed type of a direct struct field or FixedArray element, otherwise the STATIC value type of the expression. For example, an int8 field reports "int8", while a local holding its read reports "int". Folded to a string constant by the compiler: zero run-time cost, and the argument is NOT evaluated. Compare thisType, which answers the run-time type.
toInt function
ts
function toInt(value: any): intConvert value to a 32-bit signed integer. Whole numeric strings are accepted. Floats must be finite and integer-valued in range; Values must fit. Throws RangeError on conversion failure. Use tryInt for the non-throwing variant.
toFloat64 function
ts
function toFloat64(value: any): float64Convert value to a 64-bit float. Numeric strings must contain one complete number. Throws RangeError on conversion failure.
tryFloat64 function
ts
function tryFloat64(value: any): float64 | nullLike toFloat64, including numeric strings, but returns null on failure instead of throwing.
tryInt function
ts
function tryInt(value: any): int | nullLike toInt, including whole numeric strings, but returns null on failure instead of throwing. Useful for parsing untrusted input where invalid values are expected.
assert function
ts
function assert(condition: any, message?: string): voidHalt execution if condition is falsy, raising an error with the supplied message (or "Assertion failed" if none was given). Intended for invariant checks; not stripped in release builds.
exit function
ts
function exit(code?: int): voidRequest script termination with the given exit code (default 0). Pending microtasks are drained before the process exits. System.exit() is the canonical surface; this global is the legacy shim and remains supported.
sleep function
ts
function sleep(ms: int): Promise<void>Resolve after at least ms milliseconds, without blocking: other tasks, timers and window frames keep running while an await sleep(ms) is pending. ms <= 0 resolves on the next timer turn, a fraction truncates toward zero, and NaN or Infinity throw a RangeError. Under thicket run --autotest the wait is measured in virtual frame time. wait is the same function under a second name. A declaration of your own named sleep shadows this one.
wait function
ts
function wait(ms: int): Promise<void>Alias of sleep: await wait(ms) resolves after ms milliseconds.
clone function
ts
function clone(value: any): anyReturn a deep copy of value. Strings, arrays, plain objects, maps, and sets are recursively cloned; functions and class instances are returned by reference. Throws on circular references.
ts function
ts
function ts(): float64Wall-clock time in milliseconds since the Unix epoch.
NaN const
ts
const NaN: float64IEEE-754 quiet NaN.
Infinity const
ts
const Infinity: float64IEEE-754 positive infinity.
globalThis const
ts
const globalThis: anyThe global object. Provides reflective access to every binding defined at module scope. Untyped because the property set is dynamic.
undefined const
ts
const undefined: anyThe undefined value. Distinct from null.
moduleDir const
ts
const moduleDir: stringThe absolute path of the folder this module's own source file lives in, with no trailing slash. Each module sees its own: a package's widgets/button.tks gets .../widgets, not the package root. Computed when the module loads, so a moved program reports its new folder. Reading a file through it needs the ordinary fs permission.
Example:
ts
const theme = await Files.readText(Files.join(moduleDir, "theme.json"));Function class
ts
class FunctionFinal: it cannot be subclassed.
Function global — the right-hand side of f instanceof Function, which answers true for all four callable runtime types (a plain function, a closure, a native function and a bound method) and false for everything else.
Function is ALSO a type annotation (the wildcard callable, queue 081). That is a separate namespace: let f: Function and f instanceof Function both work, and neither shadows the other. new Function() still fails at runtime by design.
Generated from lang/types/builtin_globals.d.tks in the ThicketScript repository.