This Luau module provides type annotations for Roblox's signal-based instances, including RemoteEvent, RemoteFunction, BindableEvent, and BindableFunction. These annotations enhance type safety when working with client-server communication and event handling in Roblox experiences. By using these exported types, you can leverage Luau's strict typing to catch errors at development time, such as mismatched parameters in event firing or invocation.
The module is written in strict mode (--!strict) and freezes the exported table to prevent modifications.
- Type-Safe Remote Events: Separate parameter types for client-to-server and server-to-client communication.
- Type-Safe Remote Functions: Handles invocation parameters and return types for both directions.
- Bindable Events and Functions: Annotations for local (non-networked) signals with parameter and return typing.
- Compatible with Roblox's Luau type checker.
-
Clone the Repository:
git clone https://github.com/yourusername/your-repo-name.git -
Sync to Roblox Studio:
- Use Rojo or another syncing tool to import the module into your Roblox project.
- Place the
AnnotateRBXSignalInstance.luaufile in a shared module directory (e.g.,ReplicatedStorage.Modules).
-
Require the Module: In your Luau scripts, require the module like so:
local Annotate = require(ReplicatedStorage.Modules.AnnotateRBXSignalInstance)
Import the module and use the exported types to annotate your signal instances. This provides autocompletion and type checking for methods like FireClient, InvokeServer, etc.
-
AnnotateRemoteEvent<ToClient..., ToServer...>:- For
RemoteEventinstances. ToClient...: Parameters sent from server to client(s).ToServer...: Parameters sent from client to server.
- For
-
AnnotateRemoteFunction<ToClient..., FromClient..., ToServer..., FromServer...>:- For
RemoteFunctioninstances. ToClient.../FromClient...: Parameters and returns for server-to-client invocation.ToServer.../FromServer...: Parameters and returns for client-to-server invocation.
- For
-
AnnotateBindableEvent<FiredParameter...>:- For
BindableEventinstances. FiredParameter...: Parameters fired with the event.
- For
-
AnnotateBindableFunction<Parameter..., Return...>:- For
BindableFunctioninstances. Parameter...: Invocation parameters.Return...: Return values from invocation.
- For
local Annotate = require(ReplicatedStorage.Modules.AnnotateRBXSignalInstance)
local myEvent: Annotate.AnnotateRemoteEvent<string, number> = Instance.new("RemoteEvent") -- ToClient: string, ToServer: number
-- Server-side
myEvent:FireAllClients("Hello, world!") -- Valid: string
myEvent.OnServerEvent:Connect(function(player: Player, value: number)
print(player.Name, value) -- Type-checked: expects number
end)
-- Client-side
myEvent:FireServer(42) -- Valid: number
myEvent.OnClientEvent:Connect(function(message: string)
print(message) -- Type-checked: expects string
end)local Annotate = require(ReplicatedStorage.Modules.AnnotateRBXSignalInstance)
local myFunc: Annotate.AnnotateRemoteFunction<string, boolean, number, string> = Instance.new("RemoteFunction") -- ToClient: string, FromClient: boolean, ToServer: number, FromServer: string
-- Server-side
function myFunc.OnServerInvoke(player: Player, value: number): string
return "Processed: " .. tostring(value) -- Type-checked
end
-- Client-side
local result: string = myFunc:InvokeServer(100) -- Valid invocation and return typelocal Annotate = require(ReplicatedStorage.Modules.AnnotateRBXSignalInstance)
local myBindable: Annotate.AnnotateBindableEvent<boolean, string> = Instance.new("BindableEvent")
myBindable:Fire(true, "Test") -- Valid parameters
myBindable.Event:Connect(function(success: boolean, message: string)
print(success, message) -- Type-checked
end)local Annotate = require(ReplicatedStorage.Modules.AnnotateRBXSignalInstance)
local myBindableFunc: Annotate.AnnotateBindableFunction<number, string, boolean> = Instance.new("BindableFunction") -- Parameters: number, string; Returns: boolean
function myBindableFunc.OnInvoke(value: number, text: string): boolean
return value > 0 and text ~= "" -- Type-checked
end
local result: boolean = myBindableFunc:Invoke(5, "Hello") -- Valid- Roblox Studio with Luau type checking enabled.
- Luau version compatible with Roblox (Lua 5.1-based).
This project is licensed under the MIT License - see the LICENSE file for details.
- Built for the Roblox developer community to improve type safety in Luau scripts.
- Inspired by Roblox's evolving type system.