Skip to content

Allow to set named fields for generic class #1935

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
sadSader opened this issue Feb 22, 2023 · 2 comments
Closed

Allow to set named fields for generic class #1935

sadSader opened this issue Feb 22, 2023 · 2 comments
Labels
question User has a question

Comments

@sadSader
Copy link

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Linux

What is the issue affecting?

Annotations, Type Checking

Expected Behaviour

Field declaration should have priority over generic types
---@Class gener: { [string]: number}
---@field field string

Expecting gener.field to have type string.

Actual Behaviour

Field get type from generic declaration and field declaration

Reproduction steps

image

Additional Notes

I understand that generics are not fully supported yet and there are a lot of issues. Feel free to close this issue if it is a duplicate.

Log File

No response

@sumneko
Copy link
Collaborator

sumneko commented Feb 22, 2023

You can use follow instead:

---@class gener
---@field field string
---@field [string] number

@sumneko sumneko added the question User has a question label Feb 22, 2023
@sadSader
Copy link
Author

Yeah that works fine thank you. I think documentation don't mention it.

Also named field must be declared before generic field ([string]) but it is not a big deal.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
question User has a question
Projects
None yet
Development

No branches or pull requests

2 participants