Type checker is still incorrectly collapsing union types for table elements

As per the request of engineers, I’m recreating this thread to mention that this issue is still not fixed. The original thread can be found here.

The issue is identical to the one outlined in the previous thread (in fact, I noticed absolutely no change whatsoever and thought that the release was withdrawn! That’s part of why I am only reporting it again now. Apologies for the delay.)

For the sake of completeness, here’s the report again.



Issue Repro

To recreate this issue, define a structure for an element in a table. This element must be a type that is non-specific, that is, a union type between two or more types (including the usage of a nullable type e.g. number?), or any.

A simple implementation is a type with a single value:

type Thing = {
    Value: (string | number) -- The "any" keyword works as well.
}

From here, define a table that uses Thing as its element:

local Things: {Thing} = {
    { Value = 100 },
    { Value = "Hi." }
}

The result is this:
image

Expected behavior

When I define this structure, I expect it to define an object that can either take a string or a number for its value, where the result type is not uniform throughout the entire table and will instead vary between elements.

2 Likes

Thanks for the report! We’ve filed a ticket to our internal database and we’ll follow up when we have an update for you.

4 Likes