Risor vs TypeScript
TypeScript can't be executed directly. Every embedded approach transpiles to JavaScript first, then runs JavaScript in a sandboxed runtime. That's two dependencies, a two-phase pipeline, and the types are gone before execution. Risor is a purpose-built scripting language with TypeScript-aligned syntax, designed for embedding.
Embedded TypeScript Approaches
- Type-strip + JS runtime: esbuild strips types, then goja/QuickJS/V8 runs the JavaScript. Two deps, two error surfaces.
- Bundle the TS compiler: Run the TS compiler inside a JS interpreter. Self-contained but slow.
- Subprocess to Deno/Node: Full TS support but adds process-level dependency and IPC overhead.
Syntax Comparison
TypeScript:
const tier: string = (() => {
if (account.totalSpend > 10000) return "enterprise";
if (account.totalSpend > 5000) return "pro";
return "standard";
})();
const discount: number = { enterprise: 0.20, pro: 0.10, standard: 0.05 }[tier];
const total: number = lineItems.reduce((sum, i) => sum + i.price * i.quantity, 0);
const result: number = total * (1 - discount);Risor:
let tier = if (account.total_spend > 10000) { "enterprise" }
else if (account.total_spend > 5000) { "pro" }
else { "standard" }
let discount = match tier {
"enterprise" => 0.20
"pro" => 0.10
_ => 0.05
}
let total = line_items.map(i => i.price * i.quantity) |> math.sum
total * (1 - discount)Comparison
| Property | TypeScript (embedded) | Risor |
|---|---|---|
| Runtime types | None (stripped before execution) | Runtime error on type mismatch |
| Sandbox model | JS stdlib exposed (opt-out) | Empty (opt-in) |
| Feature control | Host restricts globals | Host chooses which features to enable |
| Embedding | Transpiler + JS runtime | Single function call |
| Pipes / pattern matching | No (TC39 proposals) | Yes |
| Error surface | Transpile errors + JS runtime errors | Single |
When to Choose TypeScript
- Your scripting users are TypeScript developers who won't use anything else
- Scripts are developed as files in a repository, not entered by users at runtime
When to Choose Risor
- You want simple embedding without a transpilation pipeline
- Scripts are entered by users, stored in databases, or evaluated at runtime
- You want an opt-in sandbox with host-controlled features
- You want pipe operators and pattern matching today
Learn More
- Language Overview (syntax tour for TS/JS developers)