This is on the New Luau Type Solver Beta on strict mode.
When using a singleton as the value type of a dictionary, the type solver fails to promote values to the corresponding singleton. This behavior also extends to unions of singletons.
The following code will cause Type Error: Type 'string' could not be converted into '"A"' and Type Error: Type 'string' could not be converted into '"A"|"B"|"C"' for the values in the tables.
--!strict
type test = "A"
type test2 = "A"|"B"|"C"
local t: { [any]: test } = { A = "A" }
local t2: { [any]: test2 } = {
A = "A",
B = "B",
C = "C"
}
This error does not occur when using numerical keys. Array-like tables will properly promote their types.
Expected behavior
I expect the type solver to promote each value of the table to the type, such as it would in an array.
--!strict
type test2 = "A"|"B"|"C"
local t3: { [number]: test2 } = {
[1] = "A",
[2] = "B",
[3] = "C"
}
local t4: { test2 } = { "A", "B", "C" }
In the preceding snippet, no type errors occur.