Replies: 2 comments 3 replies
-
I tested it like this and it works, I just copied the pairs annotations ---@generic T: table, K, V
---@param t T
---@param f? function
---@return fun(table: table<K, V>, index?: K):K, V
---@return T
function pairsByKeys(t, f)
end |
Beta Was this translation helpful? Give feedback.
3 replies
-
I've been testing how to annotate iterator these few days in my project, and in your case I think it should be like this: ---@generic K, V
---@param t table<K, V>
---@param f? function
---@return fun(): K, V
function pairsByKeys(t, f)
end
local t = { ccc=4, aaa=12, bbb=131 }
local iter = pairsByKeys(t) --- iter: fun() => string, integer
for i, v in pairsByKeys(t) do
--- i: string, v: integer
end
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have added this pairsByKeys function to a project : https://www.lua.org/pil/19.3.html
But it doesn't have annotations yet.
I didn't manage to build a stateless version of the function and I neither managed to get annotations working (hovering on index and value in for loop shows undefined):
Could someone help me?
Beta Was this translation helpful? Give feedback.
All reactions