tsrun
TypeScript Interpreter in Rust
A minimal TypeScript runtime designed for embedding in applications. Perfect for configuration files where you want autocompletion, type checking, and error highlighting in your editor.
Features
TypeScript for configs with IDE autocompletion - embedded in your application
ES Modules
Full import/export support with step-based module loading. Load modules from filesystem, network, or virtual sources.
Async/Await
Promises, async functions, Promise.all/race/allSettled. Pause execution for host-provided async operations.
Classes
Full class support with inheritance, static blocks, private fields, getters and setters.
Generators
function*, yield, yield*, and for...of iteration. Create lazy sequences and iterators.
Built-ins
Array, String, Object, Map, Set, Date, RegExp, JSON, Math, Proxy, Reflect, Symbol and more.
TypeScript Native
Enums, interfaces, decorators, namespaces, generics, and type annotations. Types are stripped at runtime.
Minimal & Embeddable
Small footprint with Rust and C APIs. No Node.js dependency. Ideal for config files and scripting in host applications.
Installation
Multiple ways to use tsrun in your projects
Quick Example
Run TypeScript code from Rust in just a few lines
use tsrun::{Interpreter, StepResult};
fn main() -> Result<(), tsrun::JsError> {
let mut interp = Interpreter::new();
interp.prepare(r#"
class User {
constructor(public name: string, public email: string) {}
greet() { return `Hello, ${this.name}!`; }
}
new User("Alice", "alice@example.com").greet()
"#, None)?;
loop {
match interp.step()? {
StepResult::Continue => continue,
StepResult::Complete(value) => {
println!("{}", value.as_str().unwrap()); // "Hello, Alice!"
break;
}
_ => break,
}
}
Ok(())
}
Ready to try it?
Run TypeScript code directly in your browser with our interactive playground.
Open Playground