roblox-ts provides typings for the Roblox API which are partially handwritten and partially automatically generated.
In general, everything from the Roblox API is available for use, unless it is deprecated or conflicts with TypeScript.
All global values from the Roblox API are present in roblox-ts typings.
You can find a list of available globals on the Roblox Developer Hub:
string have been intentionally omitted.
.new() functions (like
CFrame.new()) should instead be called with the
new T(...) will always compile to
undefined is a direct replacement for
nil. It can be used both as a type and a value.
Every Roblox class (
Workspace, etc.) is provided as a global/ambient type. You can use these types to describe variables, function parameters, function return types, and just about anything else in your code.
New roblox-ts users are usually confused why
RemoteEvent.OnServerEvent only allows
The reason for this is because client-to-server networking cannot be trusted. Exploiters or cheaters in your game can fire your RemoteEvent functions with whatever data they want.
If your code is expecting
points to be a
number, but the client sends a
nil value, the server will error. By sending a large number of requests very quickly which result in errors, an exploiter could crash your game server and disconnect all of your players.
Instead, you should assume your inputs can be any possible value. You can verify the arguments with a type validation package like
Alternatively, the community has created a few networking libraries which make the experience much nicer!
Deprecated types are usually not provided. Exceptions to this rule are made for API members which do not have a non-deprecated functional equivalent.
One notable exception:
Instance.Changed is not provided as it conflicts with inheritance. Usually, you want to use
If you must use
Instance.Changed, you can workaround this by asserting an intersection type with
There are a few key global interfaces which make manipulating types easier:
Services is an interface consisting of a mapping of string name to type for every Roblox service which you can fetch with
You can get a union of all service names with
And you can get a union of all service types with
CreatableInstances is an interface consisting of a mapping of string name to type for every Roblox instance which can be created with
You can get a union of all creatable instance names with
And you can get a union of all creatable instance types with
AbstractInstances is an interface consisting of a mapping of string name to type for every Roblox instance which will never be created. Generally, these are useful for functions that check inheritance like
You can get a union of all abstract instance names with
And you can get a union of all abstract instance types with
Instances is an interface consisting of a mapping of string name to type for every Roblox instance. It inherits from
Instances and also includes any type of Instance which:
- cannot be created with
- cannot be fetched with
- but can be given a reference to
DataModelis a class that cannot be created or fetched with GetService, but is given by the
AnimationTrackcan only be given a reference to via
You can get a union of all instance names with
And you can get a union of all instance types with
You can use any of these utility interfaces with generic functions. This is useful for taking an argument string and returning a matching instance type.