Typechecking recognising a mixed table as valid even when criteria not matched?

I found an amazing resource that explained typechecking simply earlier and have been playing around with it. It seems I’ve run into a case where what should be invalid and flagged by the checker is being registered as ok. Not sure if I’m misunderstanding typechecking or if I should file a bug report.

--!strict

-- Expect number key or nil and any value or nil
type Array = {[number?]: any?}

local foobar: Array = {
	"foo", "bar", "garply",
	["foo"] = "bar", -- One non-numerical key, does not get flagged
}

local barfoo: Array = {
	["foo"] = "bar",
	["gar"] = "ply",
} -- All non-numerical keys, gets flagged

Does this also when I use the array-like table special syntax.

2 Likes

I’m just going to file a bug report, this does not seem intentional or expected. Typechecking is not flagging this mixed table even though it appears invalid.

Just to check this out a second time, I changed the index type to string. Table two as expected becomes valid but table one becomes completely invalid, including the string indice.

1 Like