Typechecker warns for valid key lookup literals on tables with literal unions as keys

Not all of the following options are valid:

type keys = "Foo" | "Bar"
local tab: {[keys]: number} = {}

print(tab["Foo"]) --> Key 'Foo' not found in table '{| ["Bar" | "Foo"]: number |}'
print(tab.Foo) --> Key 'Foo' not found in table '{| ["Bar" | "Foo"]: number |}'
print(tab["Foo":: "Foo"]) --> valid

Expected behavior

I would expect all three to be valid:

type keys = "Foo" | "Bar"
local tab: {[keys]: number} = {}

print(tab["Foo"]) --> valid
print(tab.Foo) --> valid
print(tab["Foo":: "Foo"]) --> valid
3 Likes

Thank you for the report, I wanted to circle back to say that this was fixed in a recent release! On Studio 0.672, I can see that all three are appropriately accepted. Please continue to report any additional issues you run into, thanks!

Hi, it doesn’t seem to be working. Is it on an unreleased version or a beta feature? I currently have no scripting beta features enabled, and I’m fairly sure I’m on the latest version (version-012239e64a274975).

Thanks!

Ah, sorry about that, I honestly assumed that this worked in the old type solver already and that this was a New Type Solver bug report (just because of recency). Very much my bad! This is fixed in the New Type Solver specifically.

2 Likes

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