Skip to content

Generic class field #1216

@thevurv

Description

@thevurv

Describe the bug
Generics do not work when declaring classes,
I get Undefined type or alias T, and the field data does not autocomplete.

I am not sure if this is intentional or not because the <T> does highlight in the ---@class properly. I didn't see anyone using generic class fields though although I thought that'd be a very common usecase.

To Reproduce

---@class Test<T>
---@field data T

---@return Test<number>
function Test.new()
	return {}
end

local x = Test.new()

Expected behavior
I expected the field data to be defined as a number

Screenshots
image

Environment (please complete the following information):

  • OS: Windows
  • Is WSL remote? No
  • Client: VSCode

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already existsenhancementNew feature or requestfeat/LuaCats AnnotationsRelated to Lua Language Server Annotations (LuaCats)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions