-
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 |
Beta Was this translation helpful? Give feedback.
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 |
Beta Was this translation helpful? Give feedback.
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 parameters
notice that I incorrectly type
get_thing_table
asget_thing_table2
=> which causes them to be new function instead of overload