roblox-ts

Write Roblox Games with TypeScript.


import { CollectionService } from "rbx-services";

CollectionService.GetTagged("Lava").forEach(obj => {
  if (obj instanceof BasePart) {
    obj.Touched.Connect(part => {
      const character = part.Parent as Model;
      const humanoid =
        character.FindFirstChildOfClass("Humanoid");
      if (humanoid) {
        humanoid.TakeDamage(100);
      }
    });
  }
});
      

Enter Type Safety

protected name?: string

Catch a large class of errors immediately as you type them instead of 30 seconds after you hit Play. Get intelligent autocompletion for parameter types for the Roblox API and your own code. Refactor with confidence and get rudimentary documentation for free.

Static types will guide your development and save you immense amounts of time. You'll never want to go back.

Modern Syntax

x.filter(i => i > 5).map(i => i * 2)

Lua is simple. That's great for beginners, but not for people who want to get stuff done. TypeScript rocks an elegant and modern feature set with a tool for every job.

Arrow functions, object destructuring, functional data manipulation, and proper OOP structures is just a handful of what TypeScript has to offer.

Unparalleled Tooling

let unused = { name

Instantly have access to the development tools that millions of professionals use every day. Insightful static analysis with VS Code, intelligent linting from TSLint, and backed by a real package manager with versioned dependencies.

Welcome to the present.

Lua Interoperability

Lua Interoperability

Have an existing Lua code base? Don't worry. roblox-ts makes it easy to interop with existing Lua code by means of declaration files—just pair your Lua files with a special file that denotes what types it expects, and you're in action.

On the flip side, calling into TypeScript code from Lua is completely transparent and requires no extra effort or configuration.


interface BasePart extends PVInstance {
  Anchored: boolean;
  BrickColor: BrickColor;
  CFrame: CFrame;
  CanCollide: boolean;
  readonly CenterOfMass: Vector3;
  CollisionGroupId: number;
  Color: Color3;
  CustomPhysicalProperties: PhysicalProperties;
  Massless: boolean;
  Material: Enum.Material;
  Position: Vector3;
}
      

Typed Roblox API with Automatic Updates

roblox-ts offers TypeScript typings for the entire Roblox API, a hybrid of machine-generated types and hand-crafted overrides, enabling smart IntelliSense docs as you type. And whenever Roblox updates, a new version of rbx-types is automatically built and deployed, so you'll never have to wait for a human to start using new features.

NPM

Fostering an ecosystem of Roblox TypeScript packages

roblox-ts is backed by NPM, a trusted package manager with versioned dependencies. Your projects can rely on community-driven resources, and creating your own libraries is as easy as publishing a package that begins with "rbx-".

Gone are the days of submodules and half-baked Studio plugins that not everyone wants to install just to grab your library -- a centralized package manager ensures that every roblox-ts developer is on the same page.

Take a look at some of our favorite packages.


function returnsAPromise() {
  return new Promise((resolve, reject, onCancel) => {
    spawn(() => {
      let cancelled = false;

      onCancel(() => cancelled = true);
  
      while (!cancelled) {
        print("An async, cancellable operation!");
        wait(1);
      }
    })
  });
}

const promise = returnsAPromise();
wait(3);
promise.cancel();
      

Native Promises

Yielding sucks. With Promises baked in to the language, roblox-ts puts a modern async primitive at your fingertips. Promises give us a way to model any asynchronous operation without blocking, and make for easy handling when things fail.

Our Promises boast modern features like Promise inspection, finally, and cancellation with optional abort semantics.


async function getPage() {
  return HttpService.GetAsync("https://example.com")
}

async function example() {
  const html = await getPage();
  return html.gsub("rep", "lace");
}

const promise = example()
promise.then(html => html.gsub("lace", "rep"))
  .then(html => print(html))
      

async/await

Async functions are special functions that implicitly create and return a Promise when you call them. Need to yield when calling a Roblox API or a library that doesn't use Promises? No problem—you can do so safely inside of an async function. Upon calling an async function, you get a Promise back instantly which resolves when the async function returns.

When working with a lot of Promises, the .then's can really add up. await is a special keyword that will yield until a Promise resolves. Since await only works inside of async functions, you'll never unintentionally block the thread.

Rojo

Pairs with Popular Syncing Tools

The roblox-ts compiler pairs with popular syncing tools like Rojo in order to intelligently compile imports. If you change where your code will end up in your sync configuration, roblox-ts will automatically adapt on the next compile.

More Features

Join us on our journey to v1.

Right now, roblox-ts is only suitable for experimental projects because things are changing quickly. Help us shape the future this project by giving your feedback so that we can make roblox-ts the best it can be!

Get Started