[annotations] multiple return values or nil #1468
-
How do i annotate this: --- incorrectly read as (integer, integer, integer OR nil)
--- @return integer, integer, integer | nil
function foo(a)
if a then return 1, 2, 3 end
end |
Beta Was this translation helpful? Give feedback.
Answered by
carsakiller
Aug 15, 2022
Replies: 2 comments 1 reply
-
Either of these should do the trick: ---@return integer|nil
---@return integer|nil
---@return integer|nil
function test(a)
if a then return 1, 2, 3 end
end
---@return integer|nil, integer|nil, integer|nil
function otherTest(a)
if a then return 1, 2, 3 end
end As you have 3 different return values, their types will need to be explicitly defined individually. Should |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected
-
good enough i guess... even though it doesn't actually address the core of the problem being inaccurate type annotations --- incorrectly implies (nil, integer, integer), (nil, integer, nil), (nil, nil, integer),
--- (integer, nil, nil), (integer, nil, integer), (integer, integer, nil)
--- @return integer|nil
--- @return integer|nil
--- @return integer|nil
function foo(a)
if a then return 1, 2, 3 end
end |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Either of these should do the trick:
As you have 3 different return values, their types will need to be explicitly defined individually.
Should
a
be falsy, your returns arenil
... because they aren't returned.