As Roblox games become increasingly complex and larger in size, writing safe code becomes challenging with Lua. In addition, Lua is difficult to make tooling for. Roblox Studio attempts to provide things like intellisense and autocomplete, but it's mostly just guessing.
roblox-ts attempts to solve this problem by compiling TypeScript code into (Roblox flavored) Lua code.
In order to start using roblox-ts, you'll need to have NodeJS and npm installed. You can download both from here.
Next, from your command line install roblox-ts: npm install -g roblox-ts
(UNIX systems may need you to prefix this command with sudo
)
You can now run roblox-ts with the command rbxtsc
.
Usage: rbxtsc [options]
Options:
-w, --watch enable watch mode [boolean]
-p, --project project path [default: "."]
-i, --includePath folder to copy runtime .lua files to [default: "include"]
--noInclude do not copy runtime .lua files [default: false]
-v, --version show version information [boolean]
-h, --help show help [boolean]
We recommmend that you write your TypeScript in VS Code for the best experience. However, also editors like Sublime Text and Atom are supported.
-
Create a new folder and name it whatever you'd like. For example:
MyCoolProject
-
Run
npm init -y
inside of your folder. This will create yourpackage.json
file. -
Create a folder called
src
to contain your TypeScript files. -
Create a file named
tsconfig.json
in your project folder. The contents should look like this:
{
"compilerOptions": {
"outDir": "out",
"rootDir": "src",
"baseUrl": "src",
"module": "commonjs",
"strict": true,
"noLib": true,
"downlevelIteration": true,
"declaration": false,
"target": "es6"
},
"typeAcquisition": {
"enable": true
}
}
(warning: do not change these values unless you know what you are doing!)
- Create a file for syncing your compiled .lua files to Roblox Studio. If you're using Rojo, this should be a
rojo.json
file and look like:
{
"partitions": {
"include": {
"path": "include",
"target": "ReplicatedStorage.RobloxTS.Include"
},
"modules": {
"path": "modules",
"target": "ReplicatedStorage.RobloxTS.Modules"
}
}
}
You should add more partitions for the subfolders of your out
folder.
-
Run
npm install rbx-types
to install the Roblox API type definitions. -
Start roblox-ts in watch mode
rbxtsc -w
-
Run your sync program. If you're using Rojo, this is
rojo serve
-
Write code!
roblox-ts is powered by is powered by ts-simple-ast and is inspired by TypescriptToLua