Hi! I’m trying to use the Luau type annotations to write a script. Here’s what I’ve got:
local function add_entry( entry: GuiObject )
end
listObject.ChildAdded:Connect(function(child: Instance)
if child:IsA("GuiObject") then
add_entry(child)
end
end)
Which gives me the warning “Type ‘GuiObject’ could not be converted into ‘Instance’”.
Obviously child
is an Instance
so it can’t be directly passed to add_entry
which expects a GuiObject
, so the warning makes sense. But how do I tell Luau that I’ve checked to make sure child
is actually a GuiObject
so I can pass it to add_entry
? There’s no as
keyword, and I don’t know how to fix this.
I’ve searched around on Google and here on the dev forums, and as far as I can tell it’s not covered here: Type checking - Luau