lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

Disallow ? on values

Open mikuhl-dev opened this issue 1 year ago • 6 comments

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. image

Reproduction steps

---@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

mikuhl-dev avatar Aug 21 '24 04:08 mikuhl-dev