nodiscard in overloaded functions #3203
Answered
by
tomlau10
maattch
asked this question in
General Questions
|
There is a way to apply Here is a example of what i tried to do but did not worked: ---@nodiscard
---@overload fun(id: integer, autoCreate: true): table
---@nodiscard
---@overload fun(id: integer, autoCreate: false): table|nil
---@param id integer
---@return table
---@nodiscard
function get_thing_table(id) end
get_thing_table(1) -- warns about no discard
get_thing_table(1, true) -- no warnings
get_thing_table(1, false) -- no warnings |
Answered by
tomlau10
Jun 18, 2025
Replies: 1 comment 3 replies
|
If possible, you can write you function annotation in a separate meta definition file, as stated in the wiki:
demo
---@meta
---@param id integer
---@param autoCreate true
---@return table
---@nodiscard
function get_thing_table(id, autoCreate) end
---@param id integer
---@param autoCreate false
---@return table|nil
---@nodiscard
function get_thing_table(id, autoCreate) end
---@param id integer
---@return table
---@nodiscard
function get_thing_table(id) end
get_thing_table(1) -- has warnings
get_thing_table(1, true) -- has warnings now
get_thing_table(1, false) -- has warnings now |
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


it shouldn't, since it can find a definition for the signature
fun(integer, true)demo
how did you test it?
unless you define your overload function signature incorrectly (eg typo in their function names)
otherwise redundant parameters should not be shown 🤔
demo with
redundant parametersnotice that I incorrectly type
get_thing_tableasget_thing_table2=> which causes them to be new function instead of overload