Skip to content

Literal cannot match a type that it is a member of #3229

@neo451

Description

@neo451

How are you using the lua-language-server?

NeoVim

Which OS are you using?

Linux

What is the issue affecting?

Type Checking

Expected Behaviour

I get a bunch of same type errors in my workflow: https://github.com/obsidian-nvim/obsidian.nvim/actions/runs/16245747067/job/45868538877?pr=277

It just happened today.

all happening in this one type

where they are used:

--- Execute all autocommands for {event} that match the corresponding
---  {opts} `autocmd-execute`.
--- @see `:help :doautocmd`
--- @param event vim.api.keyset.events|vim.api.keyset.events[] The event or events to execute
--- @param opts vim.api.keyset.exec_autocmds Dict of autocommand options:
--- - group (string|integer) optional: the autocommand group name or
--- id to match against. `autocmd-groups`.
--- - pattern (string|array) optional: defaults to "*" `autocmd-pattern`. Cannot be used
--- with {buffer}.
--- - buffer (integer) optional: buffer number `autocmd-buflocal`. Cannot be used with
--- {pattern}.
--- - modeline (bool) optional: defaults to true. Process the
--- modeline after the autocommands [<nomodeline>].
--- - data (any): arbitrary data to send to the autocommand callback. See
--- `nvim_create_autocmd()` for details.
function vim.api.nvim_exec_autocmds(event, opts) end

--- @alias vim.api.keyset.events
--- |'BufAdd'
--- |'BufCreate'
--- |'BufDelete'
--- |'BufEnter'
--- |'BufFilePost'
--- |'BufFilePre'
--- |'BufHidden'
--- |'BufLeave'
--- |'BufModifiedSet'
--- |'BufNew'
--- |'BufNewFile'
--- |'BufRead'
--- |'BufReadCmd'
--- |'BufReadPost'
--- |'BufReadPre'
--- |'BufUnload'
--- |'BufWinEnter'
--- |'BufWinLeave'
--- |'BufWipeout'
--- |'BufWrite'
--- |'BufWriteCmd'
--- |'BufWritePost'
--- |'BufWritePre'
--- |'ChanInfo'
--- |'ChanOpen'
--- |'CmdUndefined'
--- |'CmdlineChanged'
--- |'CmdlineEnter'
--- |'CmdlineLeave'
--- |'CmdlineLeavePre'
--- |'CmdwinEnter'
--- |'CmdwinLeave'
--- |'ColorScheme'
--- |'ColorSchemePre'
--- |'CompleteChanged'
--- |'CompleteDone'
--- |'CompleteDonePre'
--- |'CursorHold'
--- |'CursorHoldI'
--- |'CursorMoved'
--- |'CursorMovedC'
--- |'CursorMovedI'
--- |'DiagnosticChanged'
--- |'DiffUpdated'
--- |'DirChanged'
--- |'DirChangedPre'
--- |'EncodingChanged'
--- |'ExitPre'
--- |'FileAppendCmd'
--- |'FileAppendPost'
--- |'FileAppendPre'
--- |'FileChangedRO'
--- |'FileChangedShell'
--- |'FileChangedShellPost'
--- |'FileEncoding'
--- |'FileReadCmd'
--- |'FileReadPost'
--- |'FileReadPre'
--- |'FileType'
--- |'FileWriteCmd'
--- |'FileWritePost'
--- |'FileWritePre'
--- |'FilterReadPost'
--- |'FilterReadPre'
--- |'FilterWritePost'
--- |'FilterWritePre'
--- |'FocusGained'
--- |'FocusLost'
--- |'FuncUndefined'
--- |'GUIEnter'
--- |'GUIFailed'
--- |'InsertChange'
--- |'InsertCharPre'
--- |'InsertEnter'
--- |'InsertLeave'
--- |'InsertLeavePre'
--- |'LspAttach'
--- |'LspDetach'
--- |'LspNotify'
--- |'LspProgress'
--- |'LspRequest'
--- |'LspTokenUpdate'
--- |'MenuPopup'
--- |'ModeChanged'
--- |'OptionSet'
--- |'PackChanged'
--- |'PackChangedPre'
--- |'QuickFixCmdPost'
--- |'QuickFixCmdPre'
--- |'QuitPre'
--- |'RecordingEnter'
--- |'RecordingLeave'
--- |'RemoteReply'
--- |'SafeState'
--- |'SearchWrapped'
--- |'SessionLoadPost'
--- |'SessionWritePost'
--- |'ShellCmdPost'
--- |'ShellFilterPost'
--- |'Signal'
--- |'SourceCmd'
--- |'SourcePost'
--- |'SourcePre'
--- |'SpellFileMissing'
--- |'StdinReadPost'
--- |'StdinReadPre'
--- |'SwapExists'
--- |'Syntax'
--- |'TabClosed'
--- |'TabEnter'
--- |'TabLeave'
--- |'TabNew'
--- |'TabNewEntered'
--- |'TermChanged'
--- |'TermClose'
--- |'TermEnter'
--- |'TermLeave'
--- |'TermOpen'
--- |'TermRequest'
--- |'TermResponse'
--- |'TextChanged'
--- |'TextChangedI'
--- |'TextChangedP'
--- |'TextChangedT'
--- |'TextYankPost'
--- |'UIEnter'
--- |'UILeave'
--- |'User'
--- |'VimEnter'
--- |'VimLeave'
--- |'VimLeavePre'
--- |'VimResized'
--- |'VimResume'
--- |'VimSuspend'
--- |'WinClosed'
--- |'WinEnter'
--- |'WinLeave'
--- |'WinNew'
--- |'WinResized'
--- |'WinScrolled'

but now if I pass a table, it says:

lua/obsidian/ui.lua:655:31 [Warning] Cannot assign `'BufAdd'|'BufCreate'|'BufDelete'|'BufEnter'|'BufFilePost'...(+135)[]` to parameter `'BufAdd'|'BufAdd'|'BufCreate'|'BufDelete'|'BufEnter'|'BufFilePost'...(+135)[]|'BufCreate'|'BufDelete'|'BufEnter'...(+136)`.
- `table` cannot match `'BufAdd'|'BufAdd'|'BufCreate'|'BufDelete'|'BufEnter'|'BufFilePost'...(+135)[]|'BufCreate'|'BufDelete'|'BufEnter'...(+136)`
- `table` cannot match any subtypes in `'BufAdd'|'BufAdd'|'BufCreate'|'BufDelete'|'BufEnter'|'BufFilePost'...(+135)[]|'BufCreate'|'BufDelete'|'BufEnter'...(+136)`
- Type `table` cannot match `'SessionWritePost'`
- Type `table` cannot match `'SessionLoadPost'`
- Type `table` cannot match `'SearchWrapped'`
- Type `table` cannot match `'SafeState'`
- Type `table` cannot match `'RemoteReply'`
- Type `table` cannot match `'RecordingLeave'`
- Type `table` cannot match `'RecordingEnter'`
- Type `table` cannot match `'QuitPre'`
- Type `table` cannot match `'QuickFixCmdPre'`
- Type `table` cannot match `'QuickFixCmdPost'`
...(+84)
- Type `table` cannot match `'BufDelete'`
- Type `table` cannot match `'BufCreate'`
- Type `table` cannot match `'BufAdd'` (param-type-mismatch)
      vim.api.nvim_create_autocmd({ "BufUnload" }, {

if I just pass one event name, it says:

lua/obsidian/workspace.lua:249:30 [Warning] Cannot assign `string` to parameter `'BufAdd'|'BufAdd'|'BufCreate'|'BufDelete'|'BufEnter'|'BufFilePost'...(+135)[]|'BufCreate'|'BufDelete'|'BufEnter'...(+136)`.
- `string` cannot match `'BufAdd'|'BufAdd'|'BufCreate'|'BufDelete'|'BufEnter'|'BufFilePost'...(+135)[]|'BufCreate'|'BufDelete'|'BufEnter'...(+136)`
- `string` cannot match any subtypes in `'BufAdd'|'BufAdd'|'BufCreate'|'BufDelete'|'BufEnter'|'BufFilePost'...(+135)[]|'BufCreate'|'BufDelete'|'BufEnter'...(+136)`
- Literal `"User"` cannot match string `"SessionWritePost"`
- Literal `"User"` cannot match string `"SessionLoadPost"`
- Literal `"User"` cannot match string `"SearchWrapped"`
- Literal `"User"` cannot match string `"SafeState"`
- Literal `"User"` cannot match string `"RemoteReply"`
- Literal `"User"` cannot match string `"RecordingLeave"`
- Literal `"User"` cannot match string `"RecordingEnter"`
- Literal `"User"` cannot match string `"QuitPre"`
- Literal `"User"` cannot match string `"QuickFixCmdPre"`
- Literal `"User"` cannot match string `"QuickFixCmdPost"`
...(+84)
- Literal `"User"` cannot match string `"BufDelete"`
- Literal `"User"` cannot match string `"BufCreate"`
- Literal `"User"` cannot match string `"BufAdd"` (param-type-mismatch)
      vim.api.nvim_exec_autocmds("User", {
                                 ^^^^^^

Actual Behaviour

Not produce these errors.

Reproduction steps

https://github.com/obsidian-nvim/obsidian.nvim/actions/runs/16245747067/job/45868538877?pr=277

of just clone https://github.com/obsidian-nvim/obsidian.nvim and run make types to see all the errors.

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