Skip to content

How to allow the injection of new fields to avoid "fields cannot be injected" error? #2356

Closed Answered by carsakiller
Dennis1000 asked this question in Q&A
Discussion options

You must be logged in to vote

There are a few options:

  1. You are allowed to inject directly into a class definition:
---@class A
local a = {}

function a:myFunction() end
  1. Define the injected field:
---@class A
---@field myFunction? fun(self: A, a: string): boolean

---@type A
local a = {}

function a:myFunction(a)
	return true
end

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Dennis1000
Comment options

@Dennis1000
Comment options

Answer selected by Dennis1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats) feat/diagnostics Related to the diagnostics feature
2 participants