Skip to content

Is it possible in an array to get the array index? #3009

Closed Answered by tomlau10
RobertSobral asked this question in Q&A
Discussion options

You must be logged in to vote

I don't quite understand the question here. 😕

I can see what you want to achieve from your given examples above, but I don't think they are conceptually correct.
AFAIK, LuaLS aims to provide type inferences on variables and table fields.
By table fields it means fields which belong to a table/class, or in general a type container.

  • In your examples, the field id belongs to the type var_cast => that's why it is showing (field) var_cast.id
  • Conceptually there is no var_cast.1 / var_cast.i type which contains a id field.
    This concept seems totally wrong to me 😕😕

Let's consider the following example, a hash table of id: integer => Object

---@class Object
---@field id integer

---@type table<…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

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

Answer selected by RobertSobral
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants