I’m still not very confident with Luau, and had a question. Is it possible to assign the type properly in this case?
type TestTable = {['Hello']: string};
local function Test(a: number): (boolean, TestTable?)
if (a > 0) then
return true, {['Hello'] = 'world'};
else
return false, nil;
end
end
local function OtherTest()
local Success, Output = Test(2);
if (Success) then
print(Output.Hello) -- "Value of type 'TestTable?' could be nil"
end
end
Right now, if “Success” is true, then the Output MUST be the table, but the type checker still thinks it could be nil and give a type warning. Is there a correct way of handling this situation? Or some way of incorporating conditions in the type definitions?