Defining a Function in a type

image

I think the problem is obvious in the image, but i want to put a function as a thing in a type definition, but luau doesn’t like it and i couldn’t find any solutions for my problem on the dev forum

Well you’re simply doing it incorrectly.

You define functions using parentheses, like this:

type myFunction = ()

But that isn’t quite enough, since you have to define the return type as well:

type myFunction = () -> number

If you want to specify that the function returns nothing, simply but another pair of parentheses:

type myFunction = () -> ()

You can also specify parameters and return types in the parentheses:

type myFunction = (myNumber: number) -> (number, string)
2 Likes

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