-
-
Notifications
You must be signed in to change notification settings - Fork 383
Closed
Labels
enhancementNew feature or requestNew feature or requestfeat/genericRelated to generic emulation featureRelated to generic emulation feature
Milestone
Description
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
Windows
What is the issue affecting?
Annotations
Expected Behaviour
---Maps `f (v, k)` on value-key pairs, collects and returns the results.
---Uses `pairs` to iterate over elements in `t`.
---<br/><em>Aliased as `collect`</em>.
---@generic TKey, TValue, TRetValue
---@param t { [TKey]:TValue } # a table
---@param f fun(value:TValue, key:TKey):TRetValue # an iterator function, prototyped as `f (v, k)`
---@return { [TKey]:TRetValue } # a table of results
---@see mapi
function M.map(t, f)
local _t = {}
for index, value in pairs(t) do
local k, kv, v = index, f(value, index)
_t[v and kv or k] = v or kv
end
return _t
end
local results = M.map({ ["num_1"] = 100, ["num_2"] = 200 }, function(value, key)
return "I am string type"
end)
查看M.map
调用的参数列表,其对应的泛型类型应该可以被解释成
TKey
-> string
TValue
-> interger
TRetValue
-> string
而变量results
的类型应可以被解释成{ [string]:string }
Actual Behaviour
无法确定TRetValue
的类型
不知道是否是我注释的方法错了,还是有意设计。
Reproduction steps
- Go to '...'
- Click '...'
- See error '...'
Additional Notes
No response
Log File
No response
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestfeat/genericRelated to generic emulation featureRelated to generic emulation feature