type-rb

module
v0.3.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2026 License: MIT

README

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

A Tour of TypeRB

Learn the language through guided, executable lessons.

TypeRB Playground

Write, run, format, and transpile TypeRB 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:

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 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

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, references, current status, and the roadmap.

License

TypeRB is available under the MIT License.

Directories

Path Synopsis
cmd
trb command
trb-wasm command
internal
ast
Package ast defines the lossless syntax tree.
Package ast defines the lossless syntax tree.
checker
Package checker resolves names, infers local declaration types, validates assignments/returns, and records a type for every portable expression.
Package checker resolves names, infers local declaration types, validates assignments/returns, and records a type for every portable expression.
cli
codegen/effectplan
Package effectplan performs whole-project call-graph analysis for backend effects that remain intentionally absent from TypeRB source signatures.
Package effectplan performs whole-project call-graph analysis for backend effects that remain intentionally absent from TypeRB source signatures.
codegen/naming
Package naming contains target-independent helpers for encoding TypeRB source names that are not valid identifiers in every backend.
Package naming contains target-independent helpers for encoding TypeRB source names that are not valid identifiers in every backend.
compiler
Package compiler owns the public compilation pipeline.
Package compiler owns the public compilation pipeline.
compilerservice
Package compilerservice owns reusable, editor-independent project snapshots.
Package compilerservice owns reusable, editor-independent project snapshots.
dbtool
Package dbtool adapts external schema management tools to TypeRB's stable database commands.
Package dbtool adapts external schema management tools to TypeRB's stable database commands.
declaration
Package declaration defines compiler-owned type information supplied by runtime-library providers.
Package declaration defines compiler-owned type information supplied by runtime-library providers.
declarationadaptertooling
Package declarationadaptertooling defines the versioned JSON report emitted by explicit declaration-adapter authoring commands.
Package declarationadaptertooling defines the versioned JSON report emitted by explicit declaration-adapter authoring commands.
formatter
Package formatter implements a deterministic, comment-preserving TypeRB printer.
Package formatter implements a deterministic, comment-preserving TypeRB printer.
ir
Package ir defines the resolved, target-independent representation consumed by every backend.
Package ir defines the resolved, target-independent representation consumed by every backend.
jobs
Package jobs models the compile-time contract shared by portable job adapters.
Package jobs models the compile-time contract shared by portable job adapters.
jobs/sqladapter
Package sqladapter owns the compile-time configuration for the official trb/jobs/sql adapter.
Package sqladapter owns the compile-time configuration for the official trb/jobs/sql adapter.
jobs/sqlstore
Package sqlstore defines the durable state model and dialect-specific SQL used by the portable SQL job adapter.
Package sqlstore defines the durable state model and dialect-specific SQL used by the portable SQL job adapter.
languageservice
Package languageservice provides editor-independent analysis used by the REPL and future browser and language-server adapters.
Package languageservice provides editor-independent analysis used by the REPL and future browser and language-server adapters.
lexer
Package lexer provides the lossless lexical layer used by both the compiler and formatter.
Package lexer provides the lossless lexical layer used by both the compiler and formatter.
lower
Package lower converts checked syntax AST into the normalized IR.
Package lower converts checked syntax AST into the normalized IR.
lsp
Package lsp adapts the shared compiler and language services to the Language Server Protocol.
Package lsp adapts the shared compiler and language services to the Language Server Protocol.
nativepackage
Package nativepackage owns cached type information derived from native target-language packages.
Package nativepackage owns cached type information derived from native target-language packages.
official
Package official loads versioned TypeRB packages bundled with the compiler.
Package official loads versioned TypeRB packages bundled with the compiler.
orm
Package orm owns the compiler-side integration for the official trb/orm package.
Package orm owns the compiler-side integration for the official trb/orm package.
packageextension
Package packageextension defines versioned, data-only boundaries used by compiler-integrated packages.
Package packageextension defines versioned, data-only boundaries used by compiler-integrated packages.
packageextensionhost
Package packageextensionhost validates package-extension data and converts it into compiler-owned semantic declarations.
Package packageextensionhost validates package-extension data and converts it into compiler-owned semantic declarations.
packages
Package packages generates target package-manager manifests from trbconfig.jsonc.
Package packages generates target package-manager manifests from trbconfig.jsonc.
parser
Package parser implements TypeRB's handwritten recursive-descent and Pratt parsers.
Package parser implements TypeRB's handwritten recursive-descent and Pratt parsers.
playground
Package playground serves the local TypeRB playground and guided tour.
Package playground serves the local TypeRB playground and guided tour.
project
Package project owns trbconfig.jsonc discovery, validation, and persistence.
Package project owns trbconfig.jsonc discovery, validation, and persistence.
projectintegration
Package projectintegration runs compile-time hooks declared by TypeRB packages without teaching the compiler pipeline their domain-specific data.
Package projectintegration runs compile-time hooks declared by TypeRB packages without teaching the compiler pipeline their domain-specific data.
repl
Package repl implements TypeRB's project-aware interactive evaluator.
Package repl implements TypeRB's project-aware interactive evaluator.
resolver
Package resolver turns syntax imports into project or compiler-known package identities before type checking.
Package resolver turns syntax imports into project or compiler-known package identities before type checking.
runtimeoperation
Package runtimeoperation describes compiler-known execution behavior for opaque runtime operations.
Package runtimeoperation describes compiler-known execution behavior for opaque runtime operations.
schemalock
Package schemalock owns the deterministic, backend-independent database schema artifact consumed by compiler integrations and command-line tools.
Package schemalock owns the deterministic, backend-independent database schema artifact consumed by compiler integrations and command-line tools.
sourcemap
Package sourcemap records backend-independent relationships between generated code and TypeRB source.
Package sourcemap records backend-independent relationships between generated code and TypeRB source.
stdlib
Package stdlib describes compiler-known portable and platform packages.
Package stdlib describes compiler-known portable and platform packages.
testsuite
Package testsuite discovers and prepares TypeRB test declarations without coupling the parser or the language server to the test runner.
Package testsuite discovers and prepares TypeRB test declarations without coupling the parser or the language server to the test runner.
toolingprotocol
Package toolingprotocol defines the versioned, read-only JSON snapshot exposed by explicit compiler tooling commands.
Package toolingprotocol defines the versioned, read-only JSON snapshot exposed by explicit compiler tooling commands.
typeprovider
Package typeprovider loads compiler-owned declaration graphs for explicitly imported platform packages.
Package typeprovider loads compiler-owned declaration graphs for explicitly imported platform packages.
typeprovider/rails
Package rails supplies TypeRB declarations for Rails and derives ActiveRecord model types from db/schema.rb.
Package rails supplies TypeRB declarations for Rails and derives ActiveRecord model types from db/schema.rb.
typeprovider/rails/schema
Package schema defines the normalized AST for the subset of Rails schema DSL that contributes model types.
Package schema defines the normalized AST for the subset of Rails schema DSL that contributes model types.
types
Package types contains target-independent semantic types.
Package types contains target-independent semantic types.
web
Package web owns target-independent compilation support for trb/web.
Package web owns target-independent compilation support for trb/web.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL