How to write annotation for an array that each element is a union of two types? #2164
-
Hi, based on this wiki: https://github.com/LuaLS/lua-language-server/wiki/Annotations#documenting-types, I'm still not sure how should I write an array, that each element is a union of two types. For example either integer or string: -- version-1
--- @type string|integer[]
-- version-2
--- @type string[]|integer[]
-- version-3
--- @alias MyStringOrInteger string|integer
--- @type MyStringOrInteger[] I guess using And what about an array, that either all of the elements are strings, or all of the elements are integers? --- @alias MyStringArray string[]
--- @alias MyIntegerArray integer[]
--- @type MyStringArray|MyIntegerArray |
Beta Was this translation helpful? Give feedback.
Answered by
carsakiller
Jun 16, 2023
Replies: 1 comment 2 replies
-
There are multiple ways that this could be typed: ---@type (string|integer)[]
local a = {} ---@type table<integer, string | integer>
local a = {} ---@alias Array<T> T[]
---@type Array<string | integer>
local a = {} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
linrongbin16
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are multiple ways that this could be typed: