How do I restrict the type of the parameter of a function?

I have learned recently that I can do this sort of stuff:

local function concatunate(a: string?, b: string?)
    return a..b
end

Restricting the arguments to be one data type. I was trying to do this earlier for functions and for tables but when I put something around the lines of:

local function DoFunction(func: function?, args: table?)
    return func(unpack(args))
end

What are the data types to make this correct?
Where can I find those to do this sort of thing?

Check out the type-checking page for Luau: Type checking - Luau (luau-lang.org) and Syntax - Luau (luau-lang.org)

Basically, a function is in the notion of (args) -> returnArgs, and a table is in the notion of {itemType} for arrays and {[keyType]: itemType} for dictionaries.

So for your function, you might have something like this:

local function DoFunction(func: () -> (), args: {string})
end

A function of type () -> () takes no arguments and returns nothing. A table of type {string} is an array of strings.

2 Likes

If i got you correctly, use

type