@type类型标记注解

注解

利用 @type 注解来标记目标变量的类型,以增强代码提示以及其它功能

../_images/type1.gif
  • 完整格式:
---@type MY_TYPE[|OTHER_TYPE] [@comment]
  • 应用目标:

    • local 变量
    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 变量
    1
    2
    ---@type Car @global variable type
    global_car = {}
    
    • property 属性
    1
    2
    3
    local obj = {}
    ---@type Car @property type
    obj.car = getCar()
    
Fork me on GitHub