What is type<T>?

in a documents pdf for the typage i view a type array = {[number]: T} but what is it ???

1 Like

They’re called generics, you can read more about it here: Type Checking | Documentation - Roblox Creator Hub

1 Like

(A quick rundown on how to use them)

Typechecking in Luau is a very useful tool. I find it tends to go hand-in-hand with OOP, since you are creating a custom type for your objects.

Let’s say we have a class PlayerData. We can make a type for that class. When making types, we define it as an array with the types we want our type to consist of.

type PlayerDataType = {
    ["Player"]: Player, --"Player" element is a player
    ["Money"]: number, --"Money" element is a number
    ["Ranks"] = {string}, --"Ranks" element is a table of strings
    ["Setup"]: (PlayerDataType) -> (number) --"Setup" is a function that takes a PlayerData object and returns a number
}

We can use export in a module to make it accessible outside of a script.

export type PlayerDataType = {
    ["Player"]: Player, --"Player" element is a player
    ["Money"]: number, --"Money" element is a number
    ["Ranks"] = {string}, --"Ranks" element is a table of strings
    ["Setup"]: (PlayerDataType) -> (number) --"Setup" is a function that takes a PlayerData object and returns a number
}

Then, something like:

local Data = require(someModule)

local PlayerData:Data.PlayerDataType = Data.new(player)
--We can get a PlayerData object and assign it as our PlayerData type

This is just a very brief rundown, please let me know if you have any questions (I don’t think I explained it very well)

3 Likes

I already knew what I was asking it was her meaning what type but in the end I understood tried! !!!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.