Function in a custom data type

i know you can create a custom datatype like that:

type NameDoNotMatter = {
-- anything here
}

so for example if we do:

type BlaBlaBla = {
D: number,
G: string
}

then if we do:

local d: BlaBlaBla

d.D -- Number
d.G -- String

but can you make a function like?

CustomDataType:FunctionName
or
anyString:Format

Yeah you can give a custom datatype functions (because they are basically tables) but not the default ones.

Also custom datatypes by roblox are created by constructors of a class thus why they can have functions that are inherited.

i have an idea!

() → () means function.
so i can do this but then in the constructor function, i define the efuncction"

What do you mean? All you need to do is define the functions of the class then let the datatype inherit it.

1 Like

also if you want to control function arguments types you can do this:

--type module
export type myFunction<Type> = (argument: Type) -> (number)
1 Like