LuaLS / LuaLS/lua-language-server

Way to annotate `@overload` only table, instead of the entire `@class`

Open
#2,826 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

```lua
---@class Class
---@overload fun(): self|Class
local Class = {}

local c = Class()

local unknown = c() -- but unknown is Class
```

I thought that was the indication `self/Class` was responsible for this

`self` for object
`Class` for table

But today I discovered that this is not so.
And in previous versions as well

In principle, this can be achieved by explicitly making

```lua
---@cast Class Class|fun(): Class
```

But for long names it is extremely monstrous

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue's Lua snippet in the language server and trace how @class and @overload annotations are interpreted. Determine how an overload can apply to the class table without changing the instance type, then add coverage for the example and verify that the inferred type of unknown is Class.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.