I created my own lightweight version of Maid, and I’m currently trying to set type checking types for functions.
One of my functions, Maid.Add
, can take either an RBXScriptConnection
, Instance, or a table - as long as it has a function under it named Destroy.
The problem here is I can’t figure out what sort of syntax I need to use for allowing extra members in the table. It’s only working if the table has Destroy, and that’s it.
function Maid:Add(Task: RBXScriptConnection|Instance|{Destroy: (...any?) -> (...any?)})
table.insert(self._tasks, Task)
return Task
end
As you can see in the image below, the bottom table warns when it ideally shouldn’t be warning. “none of the union types are compatible
”.
I was looking through the typechecking docs for Luau and didn’t have any luck. The closest thing I could find are “generics”. Would be nice if I could be pointed into the right direction with this as it’s all still quite new to me, thank you!