Union types lose information about complicated types

This behavior constantly annoys me and causes me to have to make weird types and lose intellisense.

type a = { y: Enum }
local a: a = { y = Enum.NormalId }
type b = { y: Enum } & {}
local b: b = { y = Enum.NormalId }

a works fine, b has a nonsense type error about NormalId not being able to cast into Enum. This happens for more than just enums and it’s not exclusive to unions with an empty table. Any union will do it.

3 Likes

This should be solved in the new type solver that’s currently underway. The problem here is that the current type system isn’t very smart when it sees intersection types right now, because it wasn’t built completely with set theory in mind.

2 Likes

Is there a timeline on the new system?

2 Likes