So I want to be able to get a children of an instance by typechecking but when doing that it return the properties of the instance too and I don’t know how to filter it out. I have tried doing HTTP api but it take too long to do and much code to solve
local Service = game:GetService("ServerScriptService")
type Server = typeof(Service)
local Part = Instance.new("Part")
Part.Parent = Service
local Table : Server = {}
Table. --Show all the properties and children
You can use typeof(child) and child:IsA("type") to determine the types of children at run-time. If you just want the linter to assume a type you can use child :: type but it won’t do any conversions.
If this doesn’t solve your problem could you explain more about what you are trying to do? A code snippet of iterating over children and how you want types to interact with said children?
I’m trying to replica the solution made by MagmaBurnsV but with the FindFirstChild function but it somehow doesn’t work like it supposed to. I assumed it because of the period and the colon. The purpose of doing this is to autofill a specific function parameter like the Create function from MagmaBurnsV post.
type __new = typeof(function(a:"b"|"c") end)
local Create: __new = function(Name: string)
return Instance.new(Name) -- Doesn't matter
end :: any
Create("b") --auto fill "b" and "c"
Yeah Luau is evolving quickly, that post from last year is definitely out of date.
So you need a function to return a Instance.new and have the type checker know what type it is? It might be best to declare the type of the variable at it’s call site
Well… sort of but with FindFirstChild function. Here the current code I can came up with
local Service = game:GetService("ServerScriptService")
type Server = typeof(Service.FindFirstChild) --Set typeof for FindFirstChild function
local Part = Instance.new("Part")
Part.Parent = Service
local Find: Server = function(Name:string) -- Should automatically set the FindFirstChild parameters to the functions
return Service:FindFirstChild(Name)
end
Find("") -- No autofill showing
Aha, yeah Luau doesn’t currently support that. It would be an engine-level thing, or you would have to type out all the string literals you want. The autofill for children is a relative new feature to begin with!
You might notice hovering over game:GetService objects and relative paths from script.Parent are all typed with any but still get auto-fill for properties and children. This is a pretty hacky feature at the moment, Luau can decay these to just any without autofill in a number of situations.
Ooh thanks for explaining me everything. Now I just realized it like that one old post I posted that is related to OOP but work the same thing am trying to achieve above just different approach Function as variable should work like it should