LuaLS / LuaLS/lua-language-server
Disallow ? on values
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
### How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
### Which OS are you using?
Windows
### What is the issue affecting?
Type Checking
### Expected Behaviour
`?` is not a type, and should only be used when marking fields as optional. If nil is explicitly allowed as a value, `| nil` should be used. This is in line with TypeScript.
### Actual Behaviour
`?` does not add `| nil` to the value type, and the second option should be disallowed.

### Reproduction steps
```lua
---@class Foo
---@field foo? string
---@field bar string?
---@field baz string | nil
local test = {};
function Foo()
return test.foo, test.bar, test.baz
end;
```
### Additional Notes
_No response_
### Log File
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the type-checking behavior in the Visual Studio Code Extension (sumneko.lua) using the Lua snippet in the issue. Done means `string?` is disallowed, `foo? string` remains the optional-field form, and `string | nil` explicitly permits nil.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100