EmmyLua annotations are special comments that provide type information and documentation to your Lua code. They enable static type checking, improved auto-completion, and better code documentation without changing how your Lua code runs.Annotations are written as comments using the ---@ prefix, making them completely invisible to the Lua runtime while providing rich information to language servers and development tools.
---@class User---@field id number User ID---@field name string Username---@field email string Email address---@param name string Username---@param age number User age---@return User User objectfunction createUser(name, age) return {id = generateId(), name = name, age = age}end
Catch type errors before runtime by providing explicit type information:
---@param x number---@param y number---@return numberfunction add(x, y) return x + yend-- The analyzer will warn about this:add("5", "10") -- Warning: expected number, got string
Get intelligent suggestions based on type information:
---@class Vector---@field x number---@field y number---@field magnitude fun(self: Vector): number---@type Vectorlocal vec = createVector(3, 4)-- Auto-completion now knows vec has x, y, and magnitude()vec. -- Shows: x, y, magnitude
The original and most widely used annotation format, developed for the EmmyLua plugin:
---@class Animal---@field name string Animal name---@field species string Species---@param name string---@param species string---@return Animalfunction Animal.new(name, species) return {name = name, species = species}end
---@class Config---@field host string Server hostname---@field port number Server port---@field timeout? number Connection timeout in seconds---@type Configlocal config = { host = "localhost", port = 8080, timeout = 30}