roblox-ts lets you use existing Luau scripts in your TypeScript codebase. All you have to do is define the types in a type declaration file (
roblox-ts will copy any non-compiled file (anything that isn't a
.tsx file) into your
outDir (out). This lets you place
.lua files in your rootDir (src) and they will be copied into the ourDir (out) and then synced into Roblox Studio using Rojo.
To create a type declaration file (
.d.ts) for this
.lua file, simply create a file next to it using the same name.
As an exception, if the name of your
.lua file is
init.lua, your type definition file needs to be named
Luau scripts return a single value at the end in the form of:
To model this return value in TypeScript types, we can use an "Export Assignment" statement:
And you could import it as:
If a module uses a table return containing static fields/functions, it may be preferrable to use normal exports.
Then your types could look like this:
And you could import them as:
A common way to describe custom OOP classes is with a
MyClassConstructor interface, and a
MyClass variable of type
Then in another file, you can use this as: