Skip to content

Repository files navigation

TypeRB

Warning

TypeRB is in alpha. The language, standard library, and tooling may change without notice.

TypeRB is a statically typed programming language that compiles to Go, Ruby, and TypeScript.

Try TypeRB

TypeRB documentation

Install the compiler, follow the learning path, and browse application guides, lint rules, and language references.

A Tour of TypeRB

Learn the language through guided, executable lessons.

TypeRB Playground

Write, evaluate, format, and transpile TypeRB scratch source while switching between Go, Ruby, and TypeScript output.

Docker quickstart

Run TypeRB locally without installing the compiler or a target toolchain.

With the compiler installed, launch the same tools locally:

trb tour
trb play

GitHub syntax highlighting

GitHub's built-in syntax highlighting depends on GitHub Linguist, which requires widespread real-world usage before accepting a new language or file extension. Until TypeRB becomes eligible for native highlighting, install TypeRB Syntax Highlighting for GitHub.

The extension highlights .trb file views, pull request diffs, and explicit trb and typerb Markdown code blocks on github.com.

Install

brew install type-rb/tap/trb
trb version

To build the compiler from source, use Go 1.27:

go install github.com/type-rb/type-rb/cmd/trb@latest

Container builds can copy the compiler from the matching release image without adding a Go, Ruby, Node, or Bun version to TypeRB's distribution contract:

ARG TYPERB_VERSION=X.Y.Z
FROM ghcr.io/type-rb/trb:${TYPERB_VERSION} AS typerb

FROM golang:1.27-bookworm
COPY --from=typerb /usr/local/bin/trb /usr/local/bin/trb

See TypeRB in containers for Go, Ruby, and TypeScript build and runtime layouts, supported platforms, and version pinning.

REPL

For a terminal workflow, start a typed REPL from any directory. It uses Go mode when no project configuration is present:

$ trb
trb:go> puts("Hello, TypeRB!")
Hello, TypeRB!
trb:go> 1 + 2
3 : Integer

Select another target for a one-off session:

trb repl --mode ruby
trb repl --mode typescript

Run a single file without creating trbconfig.jsonc. Standalone execution uses Go by default; select Ruby or TypeScript explicitly when needed:

def main()
	puts("Hello from TypeRB")
	return
end
trb hello.trb
trb run --mode ruby hello.trb
trb run --mode typescript --runtime bun hello.trb

When a configuration exists above the file, TypeRB follows that project instead. Standalone execution follows the selected file's explicit local imports without compiling unrelated siblings and leaves no generated files beside it. A config-free Go entry can also be built for distribution or source debugging:

trb build --compile --debug --outfile ./hello-debug hello.trb

Inside a configured project, omit the file argument and use trb build --compile to build the project entrypoint.

Create a project

Create and run a Go project:

trb init --mode go --module example.com/hello hello
cd hello

Create main.trb:

def main()
	puts("Hello from TypeRB")
	return
end

Then format and run it:

trb fmt
trb lint
trb run

Add calculator_test.trb beside application source and run portable tests:

import { describe, expect, test } from trb/std/test

describe("Calculator") do
	test("adds numbers") do
		expect(1 + 2).to_equal(3)
	end
end
trb test

The VS Code extension discovers the same suites in Test Explorer. See the testing guide for filtering and assertion APIs.

trb run builds in a temporary directory before executing the program. Use trb build when you want to keep the generated source.

Go projects can also produce an executable:

trb build --compile
./bin/hello

For a typed single-binary command-line application, trb/cli derives arguments, options, and subcommands from records and payload enums. Building currently requires the Go toolchain, but application source does not use Go APIs. See the CLI application guide.

To start a portable JSON API with file-based routes and explicit request ID and access-log middleware, generate the Web template:

trb init --mode go --module example.com/api --template web api
cd api
trb run

Targets

  • Go for native binaries and services
  • Ruby for server and application development
  • TypeScript for browser and server applications

Every target uses the same TypeRB grammar and portable semantics. A target mode selects the backend, toolchain, and package ecosystem. Target-specific APIs require explicit imports.

Documentation

Follow the learning path, or browse the documentation for application guides, lint rules, references, current status, and the roadmap.

License

TypeRB is available under the MIT License.

Releases

Packages

Contributors

Languages