RobloxLsp icon indicating copy to clipboard operation
RobloxLsp copied to clipboard

Support type inference via IsA

Open shirovian opened this issue 1 year ago • 2 comments

foo:IsA("Part") proves that foo is a Part but this code produces this error instead:

local foo = workspace:FindFirstChild("Foo")

if foo and foo:IsA("Part") then
    print(foo.Position) -- Roblox LSP Type Checking: "Key `Position` not found in type `Instance`."
end

Here it could be inferred that foo IsA Part, this would be an amazing quality of life change, I constantly have to write boilerplate to convince the type checker it will be of the already IsA asserted class in these scenarios.

shirovian avatar Mar 11 '23 10:03 shirovian

Additionally, FindFirstChild should return an optional type, and checking that it's not nil should resolve the proper Instance type.

Stefanuk12 avatar Mar 13 '23 19:03 Stefanuk12

Would really like to see this fixed. Currently it's a dealbreaker.

DazorPlasma avatar Jan 10 '24 08:01 DazorPlasma