@type type annotation¶
Note
Use @type
annotation to specify the type of the target variable, to improve completions and other functionality.
- Full format:
---@type MY_TYPE[|OTHER_TYPE] [@comment]
Target:
- local variables
1 2 3 4 5 6
---@type Car @instance of car local car1 = {} ---@type Car|Ship @transport tools, car or ship. Since lua is dynamic-typed, a variable may be of different types ---use | to list all possible types local transport = {}
- global variables
1 2
---@type Car @global variable type global_car = {}
- properties
1 2 3
local obj = {} ---@type Car @property type obj.car = getCar()
See also