How can I create a Lua type for nested tables so that each level (thing, thing.a, thing.a.b, etc.) auto-suggests a function like :func() in the editor? I also want to preserve the auto filling for the table.
thing = {
a = {
b = {
c = {
}
}
}
}
thing:func()
thing.a:func()
thing.a.b:func()
thing.a.b.c:func()
———————-
Below is a code sample that sort of works but isnt perfect.
type Inject<T> = T & {
func: (self: Inject<T>, ...any) -> (),
[string]: Inject<T>
}
local thing = {
a = {
b = {
c = {
}
}
}
}
local function addType<T>(raw: T): Inject<T>
return raw
end
local tbl = addType(thing)
tbl.a.b:func()