Custom Types: Events

Is there a way to declare custom types for event firing?

local Event ="BindableEvent")
Event.Event:Connect(function(a, b, c) --Custom types should show type of each parameter
Event:Fire(1, "string", Enum.KeyCode.X) 

Please explain more so I can help you properly :slight_smile:

also about that, if you want custom types, please use type checking like this function(bp:BasePart) or do this:

type name = string

   print(`your name is {v}`)

An example of what I mean pops up when using services such as the RunService

local RunSer = game:GetService("RunService")

--Roblox explicitly shows the parameters of t and dt to be numbers: "Connect(func(time: number, deltaTime: number) -> ()): RBXScriptConnection"
RunSer.Stepped:Connect:(function(t: number, dt: number)  <==

Is there a way to do something similar with bindable events?

If you want it to apply to the Instance and have it work across scripts without manual casting, unfortunately not. But, if you have no problem with adding :: MyEvent whenever you reference this event (e.g. you could place it at the top and use :: MyEvent to make it easier), you could go with this:

type MyEvent = BindableEvent & { Event: { Fire: (number, string, number) -> string } }

local myEvent: MyEvent = script.Parent.Event.Or.Something.Like.That


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