The backend process runs on txiki.js (tjs): file,
process, network (tjs.serve), FFI and other capabilities are exposed through
the global tjs object. As of 0.3.8 this global ships with complete
TypeScript types out of the box — app developers no longer need (and should
not hand-write) declare const tjs.
Types are provided by
@zturnlibs/tjs-types,
built from two layers:
native/txiki.js/types/src) — strictly same-source
as the runtime, so the "types say it exists, runtime doesn't have it" class
of drift cannot happen;tjs.platform) and declarations for the frontend's pure-ES2022 environment
(@zturnlibs/tjs-types/web).How to get them (pick one; usually nothing to do manually):
@zturnlibs/ztron-core (the default): core carries a
two-line reference and the tjs types activate automatically;ztron init scaffolds: the template already drops src/tjs.d.ts (two
/// <reference types="..." /> lines) and declares the devDependency;"types": ["node", "@zturnlibs/tjs-types"].In src/main.ts the tjs.* global is directly available, with full
completion and checking. The following snippet comes from
examples/hello/src/main.ts:
Note that the types reflect runtime behavior faithfully — for example
tjs.readDir returns an async-iterable DirHandle, not an array:
A hand-rolled tjs-extra.d.ts once typed that return value as an array: the
types passed, the runtime blew up — exactly why the official types are now the
single source.
The webview is a pure ES2022 environment (web-standard APIs, no Node). When adding environment declarations for frontend TS code, reference the subpath entry:
Repo contributors don't maintain types by hand:
scripts/sync-tjs-types.sh copies the vendored txiki.js's official .d.ts
files into packages/tjs-types/src/ (run it when bumping the txiki version).
Ztron's own additions live in uniquely named files (runtime-gaps.d.ts,
web-globals.d.ts) that the sync never overwrites.
Type correctness is backed end-to-end by the hello spike: 85 deterministic
checks + the FULL_OK sentinel, exit 0 (ztron check), including the
WEBSOCKET_OK check produced by the real code above.
Applicable version: ztron 0.3.8