Skip to content

Disallow ? on values #2814

@mikuhl-dev

Description

@mikuhl-dev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions