What does this mean? Because I saw this pretty much like in couple scripts.
export type Array = {[number] : T)
what does this ‘T’ means and why do they use <>
I think you mean:
export type Array <T> = {[number] : T}
Is that correct?
It’s type checking.
Yup why does it use <> . Sorry for the late respond just checked devforum
Basically, it’s a variable for types. Whatever gets put inside the <>, we substitute it into the type like it was a variable. If we assume that we required the script that exports the type, usage might look like:
local myTable : Array <string> = {
"hello", -- ok because the type is string
"bye", -- ok because the type is string
4 -- not ok because the type isn't a string
}
local myTable2 : Array <number> = {
5, -- ok because the type is a number
20, -- ok because the type is also a number
game -- not ok because the type isn't a number
}
So type tbl = {} can only be used on that script but if I use export type tbl = {} it can be used by other script, yes? Well yeah from module.
Yes, just don’t forget to use export.
I think with export when i wanna use that in the server script or local, i just need like
Let’s say i do export type tbl = {}
local myVar : Module.tbl = {} right?