Hello!
Earlier today I was working on a object-component system where you could build object prototypes using components/other object prototypes.
Heres an example of what I have right now:
local function Prototype(name: string)
return function<T>(info: T)
return function<C>(components: { C }): T & C
local objectPrototype = compilePrototype(info, components) -- magic function (don't worry about it)
objectPrototype.Name = name
return table.freeze(objectPrototype)
end
end
end
What I’m wondering is if it’s possible to have the type solver sort of “combine” all of the component types (C
) with T
. So that if I wrote something like this:
local someComponent = {
SomeProperty = 123,
}
local someOtherComponent = {
SomeOtherProperty = false,
}
local myPrototype = Prototype "MyPrototype" {
PrintSomeProperty = function(self)
return self.SomeProperty
end,
} { someComponent, someOtherComponent }
I would get autocomplete for both SomeProperty
and SomeOtherProperty
like this:
If anyone knows how to do this without just appending :: typeof(component1) & typeof(component2) etc...
(which is how I got the screenshot above…) please let me know!