How come?
I do experience the warning going off by the type checker the original poster is expriencing, and it just so happens to disappear when types are intersected instead of unionized.
Perhaps my post isn’t all clear for those who don’t actually read through the logic behind the provided explanation and additional information, so I’ll go through all that again while quoting the exact definitions as of this moment from the Type checking - Luau website:
A union type represents one of the types in this set. If you try to pass a union onto another thing that expects a more specific type, it will fail.
For this case, the ‘set’ represents the union between the TextLabel and TextButton types. Since it’s one of the types in the set, and not a specific type in the set, it will fail: accessing the Text property in the unionized type will access the figure {Text from TextLabel, Text from TextButton}, not the specific type, but the union between those (TextLabel.Text ~= (TextLabel | TextButton).Text
).
Therefore the type checker says it “Expected type table, got ‘TextButton | TextLabel’ instead” (since Text can be sourced from TextButton | TextLabel
in its unionized nature).
On the other hand,
An intersection type represents all of the types in this set. It’s useful for two main things: to join multiple tables together, or to specify overloadable functions.
For this particular case, having two Text properties from different objects is, in essence, an overload: an intersected type joins both objects, and intersects their common properties into type overloads, as opposed to unions, which wouldn’t overload anything since they come from different sources, they’re set side-by-side, not overloaded or intersected (worth the term redundancy).
As for why it doesn’t show up any warning for you, perhaps you have enabled the new Type Checker beta? I have heard (so take this with a grain of salt) it’s able to infer ambiguous expressions better and is more ‘tolerant’, more ‘smart’ in some sense, but also less rough and less direct, proper qualities of the level of strictness of a type checker I would personally use.