This works:
---@class MyClass
local thing = nil
if true then
thing = {} --[[@as MyClass]]
end
-- thing is now MyClass?
This doesn't:
---@class MyClass
local thing = nil
for i = 1, 10 do
thing = {} --[[@as MyClass]]
end
-- thing is nil
happens for while as well:
---@class MyClass
local thing = nil
while true do
thing = {} --[[@as MyClass]]
break
end
-- thing is nil
This works:
This doesn't:
happens for while as well: