How would I type check a table?

I am trying to type check a table, but local Table: table = {} doesn’t work. I also tried dictionary and array. What is the proper name? If you know, please let me know! Thanks, WE

1 Like

I don’t think Luau has the ability to let us type check for tables yet.

type regularTable = {
    [any]: any?
}
type array = {
    [number]: any?
}
local gamerTable: {[indexType]: valueType} = {}
2 Likes

Can I have an explanation of how the code works or interprets? Seems new to me.

Wait, so there isn’t simply just local Table: table = {} or local Table = {} :: table???

I can’t really explain it without taking way too long, so I would just refer to this tutorial and the luau website.

There isn’t because that would presumably be too limiting. Lets take an example of ipairs(array)

-- how do we know this only has numeric indexes? --
-- I could input a dictionary, and the type checker wouldn't know that anything is wrong --
function ipairs(array: table)

end
type array = {
    number: any?
}
-- The type checker will now yell at me for inputting a table with string indexes --
function ipairs(array: array)

end