A minimal Unit type implementation for Luau.
Primarily targets Roblox. It will probably work elsewhere, but it has not been tested on Luau, Lute, or Lune.
Unit type is a type that has exactly one value. It is useful when you need to represent "no meaningful value" in a type-safe way, similar to void in other languages but as an actual value.
Add the following to your wally.toml:
[dependencies]
Unit = "921starfish/[email protected]"Note
Due to a Wally limitation, you need to run Wally Package Types Fixer to use the Unit.Unit type.
Download src.zip from the latest release and place it wherever you like.
local Unit = require(path.to.Unit)
-- Create a Unit value
local unit = Unit.new()
-- Or use pre-created Unit value
local unit = Unit.unit
-- All Unit values are equal
print(Unit.new() == Unit.unit) -- true
-- String representation
print(tostring(unit)) -- "()"local Unit = require(path.to.Unit)
type Unit = Unit.Unit
local function doSomething(): Unit
-- do something...
return Unit.new()
endReturns a Unit value.
Alias for Unit.new().
A Unit value.
Alias for Unit.unit.
The Unit type for type annotations.