Skip to content

Commit

Permalink
Add typings for UnreliableRemoteEvent (#1118)
Browse files Browse the repository at this point in the history
  • Loading branch information
sasial-dev authored Nov 30, 2023
1 parent e083dc9 commit 0067cef
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/customDefinitions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,25 @@ interface RemoteEvent<T extends Callback = Callback> extends BaseRemoteEvent {
FireServer(this: RemoteEvent, ...args: Parameters<T>): void;
}

interface UnreliableRemoteEvent<T extends Callback = Callback> extends BaseRemoteEvent {
readonly OnClientEvent: RBXScriptSignal<T>;
/** The reason we DON'T allow you to use `Parameters<T>` here is because you can't trust data from the client. Please type-check and sanity-check all values received from the client. E.g. if you are expecting a number from the client, you should check whether the received value is indeed a number and you might also want to make sure it isn't a `NaN` value. See example code:
* ```ts
* (new Instance("RemoteEvent") as RemoteEvent<(num: number) => void>).OnServerEvent.Connect((plr, num) => {
* if (typeIs(num, "number") && num === num) {
* print(`Yay! Valid number: ${num}`);
* } else {
* print(`Bad argument received from ${plr.Name}! Exploit or bug?`);
* }
* });
* ```
*/
readonly OnServerEvent: RBXScriptSignal<(player: Player, ...args: Array<unknown>) => void>;
FireAllClients(this: RemoteEvent, ...args: Parameters<T>): void;
FireClient(this: RemoteEvent, player: Player, ...args: Parameters<T>): void;
FireServer(this: RemoteEvent, ...args: Parameters<T>): void;
}

interface RemoteFunction<T extends Callback = Callback> extends Instance {
OnClientInvoke: T | undefined;
/** The reason we DON'T allow you to use `Parameters<T>` here is because you can't trust data from the client. Please type-check and sanity-check all values received from the client. E.g. if you are expecting a number from the client, you should check whether the received value is indeed a number and you might also want to make sure it isn't a `NaN` value. See example code:
Expand Down

0 comments on commit 0067cef

Please sign in to comment.