@@ -103,13 +103,44 @@ end
103103local ErrorsOnAlreadyConnected = false
104104local IsToStringEnabled = true
105105
106+ export type Connection = {
107+ -- [string]: any,
108+
109+ Connected : boolean ,
110+ Disconnect : (self : Connection ) -> ()
111+ }
112+
113+ export type Event = {
114+ -- [string]: any,
115+
116+ IsActive : (self : Event ) -> boolean ,
117+
118+ Fire : (self : Event , ... any ) -> (),
119+
120+ Connect : (
121+ self : Event , (... any ) -> ()
122+ ) -> Connection ,
123+
124+ ConnectParallel : (
125+ self : Event , (... any ) -> ()
126+ ) -> Connection ,
127+
128+ Wait : (self : Event ) -> (... any ),
129+
130+ DisconnectAll : (self : Event ) -> (),
131+ Destroy : (self : Event ) -> (),
132+
133+ GetName : (self : Event ) -> string ,
134+ SetName : (self : Event , string ) -> ()
135+ }
136+
106137local Signal = {}
107138Signal .__index = Signal
108139
109140local Connection = {}
110141Connection .__index = Connection
111142
112- function Signal .new (name )
143+ function Signal .new (name : string ? ): Event
113144 local self = setmetatable ({
114145 _name = typeof (name ) == " string" and name or " " ,
115146 _active = true ,
@@ -150,7 +181,7 @@ local function Connect(self, func, is_wait)
150181 return connection
151182end
152183
153- function Signal :Connect (func )
184+ function Signal :Connect (func ): Connection
154185 assert (
155186 typeof (func ) == " function" ,
156187 " :Connect must be called with a function -" .. self ._name
@@ -159,7 +190,7 @@ function Signal:Connect(func)
159190 return Connect (self , func )
160191end
161192
162- function Signal :ConnectParallel (func )
193+ function Signal :ConnectParallel (func ): Connection
163194 assert (
164195 typeof (func ) == " function" ,
165196 " :ConnectParallel must be called with a function -" .. self ._name
@@ -202,7 +233,7 @@ function Connection:Disconnect()
202233 self ._prev = nil
203234end
204235
205- function Signal :Wait ()
236+ function Signal :Wait (): ( ... any )
206237 Connect (self , coroutine.running (), true )
207238
208239 return coroutine.yield ()
@@ -255,7 +286,7 @@ function Signal:GetName()
255286 return self ._name
256287end
257288
258- function Signal :SetName (name )
289+ function Signal :SetName (name : string )
259290 assert (typeof (name ) == " string" , " Name must be a string!" )
260291
261292 self ._name = name
@@ -269,7 +300,7 @@ if IsToStringEnabled == false then
269300 Signal .__tostring = nil
270301end
271302
272- function Signal :__call (_ , func )
303+ function Signal :__call (_ , func ): Connection
273304 assert (
274305 typeof (func ) == " function" ,
275306 " :Connect must be called with a function -" .. self ._name
0 commit comments