Rust and WebAssembly for TypeScript engineers: what's the benefit?
As a TypeScript engineer, you may wonder why Rust and WebAssembly (Wasm) come up so often in web development.
The Rust Programming Language book (opens in a new tab) says Rust helps you write faster, more reliable software. WebAssembly lets high-performance code run in the browser.
I updated this post in November 2026.
1. Performance
The idea that JavaScript is slow because it is interpreted is no longer accurate. The V8 engine, used by Chrome and Node.js, starts running code with the Ignition interpreter. Code that runs often is then compiled to machine code through Sparkplug, Maglev, and TurboFan or Turboshaft (V8 documentation (opens in a new tab)).
WebAssembly still has advantages. According to the W3C announcement from 2019 (opens in a new tab), much of its performance gain over JavaScript comes from consistent data types. WebAssembly also runs at close to native speed (MDN guide to WebAssembly concepts (opens in a new tab)).
The same announcement says WebAssembly can be used for video and audio codecs, graphics and 3D, multimedia and games, and cryptographic computing. The Shopify Functions guide (opens in a new tab) recommends Rust for functions that target public apps, process many order items, or are compute-heavy. The same guide says JavaScript suits prototypes, but JavaScript functions reach Shopify’s instruction limits sooner than Rust functions do.
2. Memory safety without a garbage collector
JavaScript manages memory automatically with a garbage collector (MDN guide to memory management (opens in a new tab)). Rust does not use a garbage collector, but it still keeps memory safe. Its compiler checks the ownership rules (opens in a new tab) before your program can run. Rust releases memory automatically when the variable that owns it goes out of scope.
Rust makes memory leaks hard to cause, but not impossible. The reference cycles chapter (opens in a new tab) of the Rust book gives an example using Rc<T> and RefCell<T>.
In safe code, Rust has no null. A value that might be missing uses the Option<T> type, and the compiler forces you to handle the None case before you use the value. The chapter on enums (opens in a new tab) explains why.
Many concurrency errors in Rust are caught at compile time, not when the program runs (concurrency chapter (opens in a new tab)). Borrowing rules can also prevent data races at compile time (references and borrowing chapter (opens in a new tab)).
Rust reduces many of these bugs, but it does not remove them all.
3. Interoperability with JavaScript
Rust code can be compiled into a .wasm file and used in a TypeScript or JavaScript project. The bridge is wasm-bindgen. By default, this tool also generates TypeScript type definitions for the exports from Rust (wasm-bindgen CLI reference (opens in a new tab)).
For a library, set crate-type to cdylib and add wasm-bindgen to Cargo.toml, as shown in the wasm-bindgen hello world example (opens in a new tab).
[lib]
crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "0.2"Without cdylib, cargo build for the Wasm target produces an .rlib file, not a .wasm file.
Add the Wasm target to your Rust toolchain, then compile the code:
rustup target add wasm32-unknown-unknown
cargo build --target wasm32-unknown-unknown --releaseThe .wasm file from cargo build does not yet contain the JavaScript glue code or the TypeScript type definitions. The wasm-bindgen CLI (opens in a new tab) generates both from that file.
For npm packages, use wasm-pack (opens in a new tab). The wasm-pack build (opens in a new tab) command compiles the code and generates the glue code in one step. wasm-pack build --target bundler produces an npm package for a bundler. Without --target, wasm-pack uses bundler by default.
The wasm-pack repository (opens in a new tab) now lives in the wasm-bindgen GitHub organization. The old rustwasm (opens in a new tab) organization has been archived. The Rust blog (opens in a new tab) announced the sunsetting of the rustwasm organization on July 21, 2025. When this post was updated, the latest release was v0.15.1 (October 30, 2026).
According to the wasm-bindgen deployment guide (opens in a new tab), webpack is the only bundler listed as fully supported. Rolldown also works through a plugin. Without a bundler, use --target web. That mode cannot use npm dependencies.
Outside the browser, Node.js can also run Wasm modules (MDN guide to WebAssembly concepts (opens in a new tab)). Cloudflare Workers supports Rust (opens in a new tab) through the workers-rs crate. Rust has the wasm32-wasip2 target for WASI runtimes that support the component model. The wasm32-wasip1 target is for compatibility with the older WASI preview 1. The same logic can run in the browser and on the server.
4. A better grasp of memory and concurrency
Learning Rust helps you understand low-level memory and concurrency concepts. You don’t need to free memory by hand, but you do need to understand ownership and borrowing.
I think these concepts make you write more careful code, even if you don’t write Rust every day.
5. Support and real-world use
Since November 2017, the four major browsers have supported WebAssembly, according to a Mozilla announcement (opens in a new tab).
Mozilla has used Rust in Firefox since Firefox 48 in 2016 (Mozilla Hacks note (opens in a new tab)). Shopify Functions are compiled into WebAssembly modules (Shopify Functions API reference (opens in a new tab)).
I don’t know how quickly WebAssembly will evolve. Still, Rust and WebAssembly are already used in real products.
Start small
Rust and WebAssembly do not replace TypeScript. Both are useful for small, compute-heavy parts of a project. Start with one function that you have measured and found slow. Move that function to Rust, then measure again.
