I'm wonder what is export type do?

hello everyone

I have seen some scripters use this thing… i don’t know what it’s called? and I don’t know its feature or what it does.

or what is gonna help me with

export type SettingsPlayers_Manager = {
	Value: string,
	NewValue: string,
	Character: Model
}
export type DamageHandler = {
	IsActive: boolean,
	EventName: string,
	Handler: (component: CharacterComponent, container: WCS.DamageContainer) -> (),
}

and what it’s do?

Thank you

tl;dr export allows you to access the defined type from outside a ModuleScript:

-- ModuleScript
export type nullable<T> = T?
return nil
-- A different script
local module = require(path.to.ModuleScript)

local a: module.nullable<number> = 20 -- you can access the 'nullable' type in the ModuleScript
3 Likes

there’s a few solutions here that are explained well in these posts:

1 Like

Just for a simplistic response, it lets you export a type. haha…

Types allow you to let Roblox and yourself know that a specific variable should contain a certain type of data… Such as a string or number.

Modulescripts can store types that can be accessed by other scripts like below:

Modulescript

export type my_type = string

Script

local my_module = require(my_module)

-- When coding, the type annotator will recognize this variable as a string.
local x: my_module.my_type = "Hello World"

When first learning this, I was worried about other uses that I did not know yet, but that is literally it!

3 Likes