"roblox-ts" - a TypeScript-to-Lua Compiler for Roblox

scripting

#22

Does this have type information about what’s in the game tree? It would be useful to know the names and types of children of Workspace et al. Also if this information could be preserved for clone()'s, that would be really useful for things that use a lot of prefabs (i.e. GUIs).


#23

Automatically, no. We do not take any data from Roblox Studio, so we cannot statically know the layout of your game.

In general, this is good. It makes your code more portable to not assume anything about the structure of a game.

But if you wanted this behavior, it’s pretty easy to hack it together like:

import { ReplicatedStorage } from "rbx-services";

type MyFramePrefab = Frame & {
	Child1: Frame & {
		Child2: Frame;
	};
};

const frame = ReplicatedStorage.MyPrefabFrame.Clone() as MyFramePrefab;

const child2 = frame.Child1.Child2;
print(child2.AnchorPoint);

Using as you make an assertion to the compiler about the structure of the object.

This isn’t too different than Lua. It’s just more explicit. You’re making assertions of what you think the object is when you use properties/call methods in Lua.


#24

Kinda sad that something like this isn’t already built-in to the platform. Yes, Lua is an easy-to-learn language. That doesn’t mean we can’t step it up a notch or two and add an alternative language.

Excellent work; will definitely use this.


#25

Thank you for this. Will be very helpful.


#26

Just merged in support for Roact with JSX thanks to a ton of work from @Vorlias.

Requires use of the rbx-roact package.


#27

https://roblox-ts.github.io

Huge update to our project website thanks to @evaera !
Works much better on mobile now.


#28

Can you still override the index/newindex operators?


#29

Yep, just not on class instances.

Regular objects work fine.


#30

We’ve cleaned up our documentation and moved it to the project site!

thanks to a ton of work by @evaera


#31

BREAKING CHANGES

Just published roblox-ts 0.0.23 and rbx-types 1.0.113
This is a breaking change and you’ll need to update existing code to make it work properly!

Going forward, creating Instances with the syntax new Part() will no longer work
Instead, you should use new Instance("Part")
In addition, the instanceof operator will no longer work for data types (i.e. Vector3, UDim2, etc.) or for Instances.

To replace the functionality of instanceof, I’ve added a new built-in function:
typeIs(value: any, typeName: string): boolean
It’s equivalent to going typeof(value) == typeName, but allows for type narrowing in TypeScript.
For example:

// v is some unknown data
if (typeIs(v, "Vector3")) {
    print(v.X, v.Y, v.Z); // v is a Vector3
}

This works for any given type you might want to use with Roblox’s typeof() function: nil, boolean, number, string, table, Vector3, BrickColor3, Instance, etc.

If you wanted to know if a given value is a particular type of Instance, you could use typeIs in conjunction with .IsA():

if (typeIs(v, "Instance") && v.IsA("BasePart")) {
    print(v.Size); // v is a BasePart
}