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
2 Likes