Skip to content

docs(wiki): document generic classes in @generic section#144

Merged
carsakiller merged 4 commits into
LuaLS:mainfrom
xiangnanscu:docs-generic-classes
Jul 20, 2026
Merged

docs(wiki): document generic classes in @generic section#144
carsakiller merged 4 commits into
LuaLS:mainfrom
xiangnanscu:docs-generic-classes

Conversation

@xiangnanscu

Copy link
Copy Markdown
Contributor

Description

The @generic section still says generics are limited to functions and index-signature classes (Array<T>: { [integer]: T }), and does not mention the generic-class features that landed in v3.17.0:

  • generic class inheritance with type arguments (#1929)
  • method return type resolution on generic classes (#1863)
  • generic type parameters in @overload (#723)
  • inline fun<T> generic function types in @field/@type (#1170)

This PR:

  • adds one sentence to the section intro listing the v3.17.0 additions
  • adds a Generic Class with Fields and Methods example, covering ---@class Box<T> with ---@field value T / ---@field get fun(self: Box<T>): T, and inheritance from an instantiated generic class (---@class IntegerBox: Box<integer>), with a note describing when the type parameter is substituted (members declared as ---@field entries substitute both on direct instantiation and through inheritance; separately declared methods only substitute when the receiver's type is the instantiated generic class itself)
  • adds an Inline Generic Function Type example (---@field identity fun<T>(value: T): T)

Verification

Every example was verified against lua-language-server 3.18.2 by running lua-language-server --check over probe files that assign each documented expression to an intentionally wrong type and asserting the expected assign-type-mismatch diagnostics appear (and that no diagnostics appear where substitution is documented to work).

🤖 Generated with Claude Code

xiangnanscu and others added 3 commits July 17, 2026 20:56
The @Generic section predates v3.17.0 and did not mention that classes
can declare type parameters beyond the index-signature examples. Add:

- a sentence in the intro listing the v3.17.0 additions (generic class
  inheritance with type arguments, generic parameters in @overload,
  inline fun<T> function types in @field/@type)
- an example of a generic class with fields and methods, including
  inheritance from an instantiated generic class, with a note on when
  type parameters are substituted
- an example of the inline fun<T> generic function type

All examples verified against lua-language-server 3.18.2 using --check.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@carsakiller carsakiller added the enhancement General site improvement label Jul 20, 2026

@carsakiller carsakiller left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@carsakiller
carsakiller merged commit 40163dc into LuaLS:main Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement General site improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants