TypeScript-to-Bril Compiler

Bril comes with a compiler from a very small subset of TypeScript to Bril called ts2bril.

It is not supposed to make it easy to port existing JavaScript code to Bril; it is a convenient way to write larger, more interesting programs without manually fiddling with Bril directly. It also emits somewhat obviously inefficient code to keep the compiler simple; some obvious optimizations can go a long way.


The TypeScript compiler uses Deno. Type this:

$ deno install --allow-env --allow-read ts2bril.ts

If you haven’t already, you will then need to add $HOME/.deno/bin to [your $PATH][path].


Compile a TypeScript program to Bril by giving a filename on the command line:

$ ts2bril mycode.ts

The compiler supports both integers (from core Bril) and floating point numbers. Perhaps somewhat surprisingly, plain JavaScript numbers and the TypeScript number type map to float in Bril. For integers, use JavaScript big integers whenever you need an integer, like this:

var x: bigint = 5n;

function printInt(x: bigint) {

The n suffix on literals distinguishes integer literals, and the bigint type in TypeScript reflects them.