Skip to content

Whats up with the hashtags? #3376

Closed
Closed

Description

@ChillerDragon

I see some type annotations using # and some not. Also even the wiki https://luals.github.io/wiki/annotations/ sometimes uses it and sometimes not. Is it good style? Is it more portable?

---@alias DeviceSide
---| '"left"' # The left side of the device
---| '"right"' # The right side of the device
---| '"top"' # The top side of the device
---| '"bottom"' # The bottom side of the device
---| '"front"' # The front side of the device
---| '"back"' # The back side of the device

---@param side DeviceSide
local function checkSide(side) end

https://github.com/LuaCATS/love2d/blob/765abafe49775ba52937430e2546dfc330381d6b/library/love.lua#L10-L20

---
---Gets the current running version of LÖVE.
---
---
---[Open in Browser](https://love2d.org/wiki/love.getVersion)
---
---@return number major # The major version of LÖVE, i.e. 0 for version 0.9.1.
---@return number minor # The minor version of LÖVE, i.e. 9 for version 0.9.1.
---@return number revision # The revision version of LÖVE, i.e. 1 for version 0.9.1.
---@return string codename # The codename of the current version, i.e. 'Baby Inspector' for version 0.9.1.
function love.getVersion() end

Or here one from the wiki without hashtags in the "Simple Documentation of a Class" example

---@class Person
---@field height number The height of this person in cm
---@field weight number The weight of this person in kg
---@field firstName string The first name of this person
---@field lastName? string The last name of this person
---@field age integer The age of this person

---@param person Person
local function hire(person) end

I understand it starts the description. But I don't understand when its needed and if I should use it or not.

Activity

  1. litoj commented on Mar 11, 2026

    @litoj

    The purpose seems to be primarily to help simpler parsing (like github highlighting). In some cases it determines if the next line is checked for documentation or not. I cannot tell you where I came across that, though.

    ---@class test desc
    ---@class test # desc
    ---@field f1 any desc
    ---@field f2 any # desc
    
    ---@param f1 any desc
    ---@param f2 any # desc
    ---@return any # desc
    ---@return any fieldname
    ---@return any fieldname desc
    ---@return any fieldname # desc
    function test() end
  2. CppCXY commented on Mar 11, 2026

    @CppCXY
    Member

    We can automatically infer which parts are descriptions from the doc syntax, but sometimes if your descriptor contains structures that could be parsed as continuation you must use an explicit marker to indicate where the description begins; for aliases, adding a # to attach a description is usually required

  3. ChillerDragon commented on Mar 11, 2026

    @ChillerDragon
    Author

    Okay good to know thanks. So its not some old deprecated syntax and if I aim for maximum portability I should probably develop the habit of using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions