Can Studio type-check a RemoteFunction?

I’m trying to retroactively type-check all my code, but it seems like Studio can’t check RemoteFunctions.

The most basic illustration is done with Script

--!strict
game:GetService("ReplicatedStorage").RemoteFunction.OnServerInvoke = function(player, one: string, two: number): boolean
	return true
end

and LocalScript

--!strict
game:GetService("ReplicatedStorage").RemoteFunction:InvokeServer(

Here, I expect Studio to suggest the argument names and types from the function I assigned in the Script. It can only retrieve the argument format for :InvokeServer().

Is there any way to hint the types to Studio?

1 Like

No, you shouldn’t do this, even though you can. The reason is simple - just look at it from the engine’s perspective - you (or rather, anyone who modifies the client) can send anything from this client, and a cheater can send a number instead of the expected string, and so on. Therefore, attempting to do so is logically incorrect.

local a: RemoteFunction = "Here"
local b: (self: RemoteFunction, one: string, two: number) -> (boolean?) = a.InvokeServer
-- first `(...)` is args what u want to give, second `(...)` is args than return server
local c = b(a, "hi!", 2) -- c is boolean?

Although I would also type it in general, due to my love of strict typing (which doesn’t make much sense in a dynamically typed language in general except when you want your code to be “pretty” for someone else to use without looking inside), don’t forget to validate that the first argument is a string and so on.

  • and yes, you might be wondering why I’m passing the RemoteFunctioin itself as the first argument. This is because we need to pass the object on which the method was called, otherwise the luau interpreter won’t understand anything. In other words, object:method() is equivalent to object.method(object) or class.method(object)
1 Like

So you can only have Studio suggest arguments if you add types to a variable set to InvokeServer on the client?

Also, as far as my remotes are concerned, I believe they error if a wrong type is submitted anyway, but I will implement correctness checks.

Yes, that’s right.

Спойлер

Этот текст будет скрыт

To ensure the type correctness you can use an awesome tool created by osyrisrblx, called “t”.
It’s an awesome tool to ease the process of ensuring correct types, and it’s also recommened to use by Roblox.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.