In type checking for tables, should I do : table or : {}

Title is self explanatory. I read in luau docs that there are 8 primitive types and that one of them is table, but I saw someone doing : {} in coding. I’m not sure which way to do it.

2022-08-13 07_14_15-ModuleScript - Roblox Studio
: {} doesn’t show waring

while

2022-08-13 07_14_36-ModuleScript - Roblox Studio
: table does.

someone clarify this for me. thanks.

1 Like

table is just a global, {} is the proper way to define a table for typechecking:

local function expect_table(t: {[any]: any}) 
   -- This expects a table of any index type and any value type
end
4 Likes

I see… Well luau docs are just different breed I guess

“{}” is used for tables in type annotation. at least for roblox

You can also explicitly define a type with the name of table, if you want to use it:

type table = {[any]: any}

local function expect_table(t: table) 
   
end

Though naming it ‘table’ would be frowned upon because it would override the default variable of the same name.

It actually wouldn’t:

image

image

You can access and use the table global the same as before, It just defines a new type named table (which may look confusing)

1 Like

Yeah I would love if roblox could follow lowercases for the typechecking and also just for it to be table.
Typechecking in current state looks kinda messy because any roblox typechecking is in PascalCase,

1 Like

Well if they were to use the keyword “table”, how would you specify each index and value?

Elaborate I don’t know what you mean

What they mean is that you currently annotate a table’s keys/values within the table constructor {} itself, if tables were annotated via ‘table’ how would its keys/values be annotated?

local t : {[string] : boolean} = {Key = true}
local t : table = {Key = true} --How would you annotate the keys/values?

Yeah good point… I didn’t think about that