Skip to content

[annotations] multiple return values or nil #1468

Answered by carsakiller
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

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 a be falsy, your returns are nil... because they aren't returned.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected
Comment options

You must be logged in to vote
1 reply
@carsakiller
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant