typestrip 0.1.0

A TypeScript type eraser and downleveler for Zena programs: the engine behind @nibling/typestrip

Readme Files Dependencies Versions

typestrip#

A TypeScript type stripper in a small, dependency-free WebAssembly module.

typestrip erases types the way ts-blank-space and Node's type stripping do. Every JavaScript character stays where it was, so the output needs no source map. It streams, so memory stays flat at any input size. The engine is written in Zena and compiled to WasmGC with zero imports. It is 13.9 kB gzipped.

import { transform, transformSync } from "@nibling/typestrip";

await transform("let x: number = 1;"); // "let x         = 1;"
transformSync("let x: number = 1;"); // the same, synchronously

// Stream chunks, a Node Readable, or a web ReadableStream.
for await (const piece of transform(fs.createReadStream("input.ts"))) out += piece;

Modes#

Mode Does Preserves
erase (default) Erases erasable syntax. Reports enum, instantiated namespace, parameter properties, import =, export =, and <T>x casts. Every offset
downlevel Also down-levels that syntax, matching ts.transpileModule at runtime. Pass sourceMap: true for a source map of the moved columns. Every line; columns outside converted constructs
await transform(src, { mode: "downlevel" });

Pass jsx: true for .tsx input, in either mode. Erase mode keeps the JSX. Downlevel mode writes it for the automatic runtime (react/jsx-runtime), or for the classic one with jsx: "classic" (React.createElement). jsx also takes oxc's option names: { runtime, importSource, pragma, pragmaFrag }.

Unsupported syntax throws an UnsupportedSyntaxError with Node's ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX code. Pass onError to collect it instead. docs/modes.md has the full rules and examples of downlevel output.

Size#

There is one engine per feature set, and a call loads only the one its options need, lazily, on its first call. Nothing loads at import.

What you ship Raw gzip -9 brotli -11
Erase mode, with or without JSX: erase.wasm + wrapper 34.5 + 9.9 kB 13.9 + 4.1 kB 12.6 + 3.7 kB
Downlevel mode: downlevel.wasm + wrapper 49.4 + 9.9 kB 20.5 + 4.1 kB 18.5 + 3.7 kB
Downlevel mode writing JSX: downlevel-jsx.wasm + wrapper 60.5 + 9.9 kB 25.5 + 4.1 kB 22.8 + 3.7 kB

The wrapper is src/index.js bundled with esbuild --bundle --minify --format=esm. The browser entry is the same size. Every engine needs WasmGC and wasm SIMD.

Speed#

On a 20MB sample of real-world TypeScript from 17 open-source projects (Apple M1, Node 24):

Tool MB/s gzip
typestrip 69.6 15.1kB
@swc/wasm-typescript (strip-only) 27.3 1.39MB
amaro (strip-only) 25.5 1.12MB
ts-blank-space 16.9 1.03MB

typestrip also beats oxc-transform, a native addon, in downlevel mode. It does less work per byte: one forward pass over the bytes, no syntax tree, and no code generation. docs/benchmarks.md has every tool, both modes, and the method.

Correctness#

Erase mode is judged against ts-blank-space, on positions, parsed JavaScript, error positions, and streamed output. It passes all 11,736 files of TypeScript 6's own sources and test suites. Downlevel mode is judged against ts.transpileModule by evaluating both outputs. docs/correctness.md lists every suite, its last result, and the open bugs.

Docs#

Contributing#

CONTRIBUTING.md covers setup, building, testing, and the debug tools.

License#

MIT

3.5 KiB Raw
// GENERATED by scripts/gen/hooks.mjs for the downlevel-jsx engine.
import {
  init as hInit, enumStart as hEnumStart, enumStep as hEnumStep, namespaceStart as hNamespaceStart,
  namespaceEnd as hNamespaceEnd, exportModifier as hExportModifier, dropPending as hDropPending,
  hookSp as hHookSp, blockHook as hBlockHook, functionHead as hFunctionHead, className as hClassName,
  varFlags as hVarFlags, declNames as hDeclNames, importEquals as hImportEquals, exportAssign as hExportAssign,
  classOpen as hClassOpen, classEnd as hClassEnd, paramProp as hParamProp, ctorBody as hCtorBody,
  castErase as hCastErase,
  ambientVar as hAmbientVar,
  moduleEsmSeen as hModuleEsmSeen, moduleCjsSeen as hModuleCjsSeen,
} from './downlevel.zena';
import {
  pragma as jPragma, pragmas as jPragmas, open as jOpen, quoted as jQuoted, ns as jNs, piece as jPut, text as jText,
  str as jStr, auto as jAuto, textSegs as jTextSegs, callee as jCallee, keyEnd as jKeyEnd,
  key as jKey, keyBegin as jKeyBegin, tail as jTail,
} from './jsx.zena';
export function init(): void { hInit(); }
export function enumStart(): void { hEnumStart(); }
export function enumStep(): void { hEnumStep(); }
export function namespaceStart(start: i32, lead: i32): void { hNamespaceStart(start, lead); }
export function namespaceEnd(values: i32): void { hNamespaceEnd(values); }
export function exportModifier(): i32 { return hExportModifier(); }
export function dropPending(): void { hDropPending(); }
export function hookSp(): i32 { return hHookSp(); }
export function blockHook(): boolean { return hBlockHook(); }
export function functionHead(n: i32): void { hFunctionHead(n); }
export function className(): void { hClassName(); }
export function varFlags(k: i32): i32 { return hVarFlags(k); }
export function declNames(flags: i32): boolean { return hDeclNames(flags); }
export function importEquals(): void { hImportEquals(); }
export function exportAssign(): void { hExportAssign(); }
export function moduleEsmSeen(): boolean { return hModuleEsmSeen(); }
export function moduleCjsSeen(): boolean { return hModuleCjsSeen(); }
export function mapOn(m: i32): i32 { return (m >> 4) & 1; }
export function classOpen(ext: i32): void { hClassOpen(ext); }
export function classEnd(): void { hClassEnd(); }
export function paramProp(): void { hParamProp(); }
export function ctorBody(): void { hCtorBody(); }
export function castErase(m: i32, end: i32, ctxFlags: i32): i32 {
  return hCastErase(m, end, ctxFlags);
}
export function ambientVar(n: i32): i32 { return hAmbientVar(n); }
export function jsxOn(): boolean { return true; }
export function jsxPragma(addr: i32, a: i32, b: i32, c: i32, auto: boolean): void { jPragma(addr, a, b, c, auto); }
export function jsxAuto(): boolean { return jAuto(); }
export function jsxPragmas(end: i32): void { jPragmas(end); }
export function jsxOpen(frag: boolean): void { jOpen(frag); }
export function jsxQuoted(a: i32, b: i32): void { jQuoted(a, b); }
export function jsxNs(a1: i32, b1: i32, a2: i32, b2: i32): void { jNs(a1, b1, a2, b2); }
export function jsxPut(k: i32): void { jPut(k); }
export function jsxTextSegs(a: i32, b: i32): i32 { return jTextSegs(a, b); }
export function jsxText(a: i32, b: i32, comma: boolean): void { jText(a, b, comma); }
export function jsxCallee(o: i32, kids: i32, k: i32): void { jCallee(o, kids, k); }
export function jsxKeyBegin(src: i32): void { jKeyBegin(src); }
export function jsxKeyEnd(o: i32): void { jKeyEnd(o); }
export function jsxKey(): void { jKey(); }
export function jsxTail(): void { jTail(); }
export function jsxString(a: i32, b: i32): void { jStr(a, b); }
none
VersionPublishedDependenciesApproved by
0.1.0 2026-11-22 none
0.0.2 2026-11-21 none