Luau does not simplify (number? & number?) to number?

type A = {
	x: number?,
}
type B = {
	x: number?,
}
type C = A & B
local obj: C = {
	x = 3,
}
local x: number = obj.x or 3

Take this code for example. This produces a warning:


even though it is completely valid code. This is an oversimplified example, but it happens in more complex scenarios as well.

Expected behavior

No error should be shown and (number? & number?) should simplify into just number?.
There are many more circumstances like this and it is just not to do with numbers, it could be any type.

4 Likes

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!

2 Likes

Hey there, just wanted to post a quick update on this! We’ve been working really hard on some big type system changes that address this problem amongst many others. Stay tuned!

2 Likes