Reproduction Steps
To reproduce this issue, create three tables: an array-like table, a dictionary and a mixed table (table that has elements of both styles). Give all of these tables the same type. To start make sure the type is set up for an array-like table. Do not use the special shorthand syntax as the key type needs to be changed to reproduce the issue.
You only need the mixed table to reproduce the issue so the array-like table and dictionary are optional but they give a point of reference when observing how the type behaves with other table types.
Your code should look like the following:
--!strict
type MyType = {[number]: any?}
local array: MyType = {
1, 2, 3, 4, 5
}
local dictionary: MyType = {
["foobar"] = "hello",
["barfoo"] = "world"
}
local mixed: MyType = {
1, 2, 3, 4, 5,
["foobar"] = "hello",
["barfoo"] = "world",
}
To reproduce the bug, change the key type from number to string.
Expected Behavior
If my understanding of typechecking is correct then the two string indices of mixed should be flagged when the key type of MyType is number and they should be valid when the key type is string.
Actual Behavior
When the key type of MyType is number, the mixed table including its string indices is recognised as acceptable. When the key type of MyType is string, the whole mixed table including the string indices are flagged. The array and dictionary tables behave as expected and get flagged respectively when the key type does not match. Below is media demonstrating the issue.
Workaround
Union typing: accepting a union between number and string will not flag any of the tables as they all successfully meet the criteria.
type MyType = {[number | string]: any?}
Issue Area: Studio
Issue Type: Other
Impact: Low
Frequency: Constantly
Date First Experienced: 2021-05-31 21:09:00 (-04:00)
Date Last Experienced: 2021-06-02 03:00:00 (-04:00)