You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As the firing of these Roblox instances have no way to enforce type safety, I feel it's cleanest to make developers validate the types that are received.
In this below example, no errors are detected - everything is fine. That player variable could be passed into another function and cause a really weird error somewhere far away from the event.
localbindableEvent:BindableEventbindableEvent.Event:Connect(function(player:Player)
-- the player is actually a string, but the dev is expecting a playerend)
bindableEvent:Fire(Players.LocalPlayer.Name)
What I propose is that it's better for the code to accept this uncertainty, and refine it in the following code. For example:
localbindableEvent:BindableEventbindableEvent.Event:Connect(function(player:unknown?)
assert(typeof(player) =="Instance", `player is not instance, got type "{typeof(player)}"`)
assert(player:IsA("Player"), `player is not player, got class "{player.ClassName}"`)
-- the type is now certainly a player, or has given the developer a clear error at the earliest point possibleend)
bindableEvent:Fire(Players.LocalPlayer.Name)
I feel this handling of it is safe and more accurate to what's actually happening in the code, similar to the improvement made to attributes earlier.
Thank you for your time!
The text was updated successfully, but these errors were encountered:
nightcycle
changed the title
RemoteEvent / BindableEvent / RemoteFunction / BindableFunction should be "unknown" instead of "any"
RemoteEvent / BindableEvent / RemoteFunction / BindableFunction should be "unknown?" instead of "any"
Oct 20, 2024
The main reason I am hesistant about this is from a user experience PoV, as switching this from any to unknown will lead to loads of type errors throughout existing code bases I imagine.
As the firing of these Roblox instances have no way to enforce type safety, I feel it's cleanest to make developers validate the types that are received.
In this below example, no errors are detected - everything is fine. That player variable could be passed into another function and cause a really weird error somewhere far away from the event.
What I propose is that it's better for the code to accept this uncertainty, and refine it in the following code. For example:
I feel this handling of it is safe and more accurate to what's actually happening in the code, similar to the improvement made to attributes earlier.
Thank you for your time!
The text was updated successfully, but these errors were encountered: