@ttsc/wasm
ttsc is the standalone TypeScript-Go compiler β see Setup if you havenβt installed it yet.
@ttsc/wasm is the in-browser runtime for ttsc. It packages the same Go-backed engine the CLI ships with β built for GOOS=js GOARCH=wasm β alongside a JS boot helper and an in-memory filesystem bridge. Use it to embed a ttsc playground in your own site, or to extend the wasm with your plugins.
API stability: experimental until v1.0. Public signatures (
Plugin.Run, thehost.Exposeargv shape, the JSITtscApisurface, the linker-symbol-ldflags "-X ..."contract) may change between minor releases.
When to reach for it
- You want a typia or
@ttsc/lint-style playground on your docs site. The same engine the CLI uses, no server round-trip. - Youβre a plugin author publishing a transform plugin and youβd like a hosted demo so readers can try
your-pluginwithoutnpm install. - Youβre building a learning surface (workshops, tutorials) where users edit TypeScript and need real type-checking in-browser without a backend.
What ships
| Artifact | What it is |
|---|---|
dist/ttsc.wasm | The no-plugin sanity binary built from cmd/ttsc-wasm/main_wasm.go. Exposes build / check / transform only. |
dist/wasm_exec.js | Goβs runtime loader. Required by every @ttsc/wasm consumer. |
host/ (Go) | The host.Expose helper plugin authors import from their own main_wasm.go. |
lib/, src/ (TS) | bootTtsc(...), createMemFS(...), typed ITtscApi surface. |
vendor/shim/* | Pack-time vendored copy of packages/ttsc/shim/. Required so the published Go module resolves under node_modules/@ttsc/wasm/. |
Minimum viable boot
import { bootTtsc } from "@ttsc/wasm";
const { api, host } = await bootTtsc({
wasmUrl: "/wasm/ttsc.wasm", // host this from your static site
wasmExecUrl: "/wasm/wasm_exec.js",
apiName: "ttsc",
});
host.writeFile("/work/tsconfig.json", '{"compilerOptions":{"strict":true}}');
host.writeFile("/work/src/index.ts", "export const x: number = 1;");
const result = await api.build({ cwd: "/work" });
console.log(result.result);A Web Worker is required β Goβs syscall/js blocks the runtime while the wasm is alive; running on the main thread freezes the page.
Going further
For the full surface β building a custom wasm with your plugins linked in, the -ldflags "-X ..." version-stamping contract, the published-tarball Go module layout, the native-build sibling β read the @ttsc/wasm README on GitHub.
See also
- Plugin Development β write the plugin youβd link into a custom wasm.
- Plugin Development Β· TS-Go concepts β Program / Checker / VFS background.
- Playground β the reference consumer built on top of
@ttsc/wasm.