Syntax
type Entity = Named & PositionedExamples
Luau intersection record types
Run as a standalone current Luau script, or as a Script in Roblox Studio ServerScriptService. No Roblox engine APIs are required; type-annotated syntax is not standard Lua.
--!strict
type Named = {name: string}
type Positioned = {x: number, y: number}
type Entity = Named & Positioned
local function describe(entity: Entity): string
return entity.name .. "@" .. tostring(entity.x) .. "," .. tostring(entity.y)
end
print(describe({name = "spawn", x = 2, y = 5}))- Output: spawn@2,5. The supplied record satisfies both the name and coordinate requirements.
Best practices
- Avoid contradictory property types in intersections. Use a union when a value may have either shape rather than both.
Runtime & versions
Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Luau documentation