lua-language-server
lua-language-server copied to clipboard
Using a union of string literals as a table key doesn't force use of the keys
How are you using the lua-language-server?
NeoVim
Which OS are you using?
Linux
What is the issue affecting?
Type Checking
Expected Behaviour
---@alias SomeUnion
--- | 'a'
--- | 'b'
---@type table<SomeUnion, number>
local a
should work roughly like
---@class (exact) SomeUnion
---@field a number
---@field b number
local a
Actual Behaviour
Reproduction steps
---@alias SomeUnion
--- | 'a'
--- | 'b'
---@type table<SomeUnion, number>
local a = {
c = "should be invalid"
}
Additional Notes
No response
Log File
No response
Here is how it would look like in TypeScript:
type SomeUnion = 'a' | 'b'
type SomeTable = Record<SomeUnion, number>
const a: SomeTable = {
}
const b: SomeTable = {
a: 2,
b: 3,
c: 4,
}
There's a lot of issues with the support for aliases/custom types. Seems to be an experimental feature that doesn't have full support.
As an example, there's no information in the documentation I linked that informs what the grammar for alias is incomplete. (For example, you can put some tokens like +
and >
after the |
and it will work and change how the autodoc is formatted.
Would like first class support for this, though I suspect it is coming with the rework.
see also #2610, #1861