5uphi
(5uphi)
November 24, 2022, 4:17pm
#1
Hey guys so I have 3 types in my module
export type Constructor = {
new: () -> Signal,
}
export type Signal = {
Connect: (self: Signal, func: (...any) -> ()) -> Connection,
Once: (self: Signal, func: (...any) -> ()) -> Connection,
Wait: (self: Signal) -> ...any,
DisconnectAll: (self: Signal) -> (),
Fire: (self: Signal, ...any) -> (),
}
export type Connection = {
--Signal: Signal?, -- Adding this breaks it
Disconnect: (self: Connection) -> (),
}
The Constructor type has a function called new
that creates the Signal type and the Signal type has a function called Connect
that creates the Connection type
up to now everything work fine but the problem happens when I try to have a property inside the Connection type that is the type Signal it does not seam to like to have a type that it was created by
is there a way to make this work?
PostVivic
(Vivic)
November 24, 2022, 4:25pm
#2
what do you mean “breaks it?”
I attempted the same thing and no errors
my only question is do you really need the Signal as a nullable value?
because then the code will scream at you if you try to run anything on it because it “could be nil”
5uphi
(5uphi)
November 24, 2022, 4:30pm
#3
when the connection is disconnected the signal property becomes nil
PostVivic
(Vivic)
November 24, 2022, 4:33pm
#4
kind of a dumb question, but do you have signalModule returning a constructor type?
IE
return signalModule::Types.Constructor
5uphi
(5uphi)
November 24, 2022, 4:34pm
#5
the module returns the constructor like this
local constructor: Constructor = {}
return table.freeze(constructor)
1 Like
PostVivic
(Vivic)
November 24, 2022, 4:43pm
#6
this is actually a really peculiar type definition issue.
I think its an issue with the Constructor class for some reason. I would just let Luau define it regularly
I have literally no idea why this doesn’t work as it obviously should
1 Like
5uphi
(5uphi)
November 24, 2022, 4:47pm
#7
yup that works for me as well
and also strange why it does not work the other way
iv posted a issue on github here: Can not set type to type that created type · Issue #758 · Roblox/luau · GitHub
system
(system)
Closed
December 8, 2022, 4:48pm
#8
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.