Is there a way to create instance structures with TypeChecking without actually creating an instance?

Hi,

I’m wondering, in type checking, if it’s possible to create a type that is just a tree of instances without actually creating instances?

Currently, you can do this by doing typeof() on an instance but the problem is that I actually have to create an instance which I fear could be unwise with respect to memory.

When I say Instance structures, I mean literally a hierarchy of instances, so imagine folders inside of folders with parts inside of these folders and values etc…

I’m only doing this for the autocompletion feature so it isn’t a big deal if it isn’t possible, I can just destroy the instances at runtime but best case scenario would be to not actually have to create any instances.

Thanks!

1 Like

As far as I’m aware, it is not currently possible to strongly type an Instance’s children other than what roblox can determine from the in-game structure.

Would be happy to be proven wrong, though.

Edit: I can’t test myself atm, but does something like this work?

local a = Instance.new("Part")
local b = Instance.new("Part")
b.Name = "B"
b.Parent = a

local aWithBChild: typeof(a) & { B: typeof(b) }
1 Like

Nope :(
image

Edit: I was indexing the wrong thing, aWithBChild:FindFirstChild('test') doesn’t give any autocompletion either.

Edit again, this also yields no results:

local aWithBChild: typeof(a) = a
aWithBChild:FindFirstChild('test')
a:FindFirstChild('test')