New Type Solver Type Errors On Singletons As Dictionary Value

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.

Hello, and thank you for beta testing the new type solver! We’re aware of this as a specific issue, we’ll keep you in the loop as we fix this bug.

Just checking back in; we should have a fix for this landing soon, apologies for the wait!

1 Like

Hello! I believe this has been fixed for some time now, the following snippet:

--!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"
}

… now has no type errors, as is expected. Please let us know if you run into any other issues with the new type solver!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.