Type checker disallows writing to fields after refining optional type

The following code should have no type errors because in both union options we have the same fields. However, the type checker doesn’t like it, and for both lines gives the error Expected type table, got 'A1 | A2' instead

type A1 = {
	B: number?;
	C: number;
}
type A2 = {
	B: number?;
	C: number;
}
type A = A1 | A2
local A: A = nil
if not A.B then
	-- These two lines have type errors.
	A.B = 1
	A.C = 2
end

This is just an acknowledgment announcement!

We’ve filed a ticket into our internal database for this issue, and we will update you when we have further information!

Thanks for the report!

1 Like