What does export do?

I recently saw a global variable but I don’t know why and what it’s used for. I saw this piece of code:

export type Listener = {Command : string, Callback : () -> nil, StopListening : () -> nil}

What does it do?

1 Like

It exports the type Listener (for type annotations) so it can be used in other modules using require.

Mind giving me an example of how to require it in other modules?

An example, with two scripts, one of them being ModuleScript while other could be any script.

Module 1

local ModuleScript1 = { }
export type Point { x: number, y: number }

function ModuleScript1.example1(): Point
        return {
                x = 1,
                y = 2,
        }
end

return ModuleScript1

LocalScript 1

local ModuleScript1 = require(ModuleScript1) -- now the type Point is imported from ModuleScript1, to access it use the dot syntax

local myVariable: ModuleScript1.Point = ModuleScript1.example1() -- myVariable annotated with the type Point
5 Likes