How to annotate table that uses indexing and not field names. #2809
Answered
by
tomlau10
vnaoScriptHub
asked this question in
Q&A
-
New LuaLS user here. One example of an API return table that I'm trying to annotate as a class. VersionInfo = {
["FileVersion"] = {
[1] = 2,
[2] = 9,
[3] = 7,
[4] = 59074,
},
} As you can see below, not sure how to annotate this. ---@class VersionInfo
VersionInfo = {
---@class FileVersion
---@field ??? integer Major version.
---@field ??? integer Minor version.
---@field ??? integer Revision number.
---@field ??? integer Build number.
FileVersion = {}
} |
Beta Was this translation helpful? Give feedback.
Answered by
tomlau10
Aug 19, 2024
Replies: 2 comments 4 replies
-
use the ---@class VersionInfo
VersionInfo = {
---@class FileVersion
---@field [1] integer Major version.
---@field [2] integer Minor version.
---@field [3] integer Revision number.
---@field [4] integer Build number.
FileVersion = {}
}
local a = VersionInfo.FileVersion[1] --< integer
local b = VersionInfo.FileVersion[5] --< unknown |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
vnaoScriptHub
-
So that works but for some reason the comments don't show up. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use the
[index]
syntax