Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a union of string literals as a table key doesn't force use of the keys #2495

Open
kamoshi opened this issue Jan 23, 2024 · 3 comments

Comments

@kamoshi
Copy link

kamoshi commented Jan 23, 2024

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

image

Reproduction steps

---@alias SomeUnion
--- | 'a'
--- | 'b'

---@type table<SomeUnion, number>
local a = {
  c = "should be invalid"
}

Additional Notes

No response

Log File

No response

@kamoshi
Copy link
Author

kamoshi commented Jan 23, 2024

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,
}

image

@kamoshi kamoshi changed the title Using an union of string literals as table key doesn't force use of the keys Using a union of string literals as a table key doesn't force use of the keys Jan 23, 2024
@bavalpey
Copy link
Contributor

bavalpey commented Feb 9, 2024

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.

@mycroftjr
Copy link

see also #2610, #1861

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants