Skip to content

Annotation Help: Mutated Classes #3069

Answered by tomlau10
NickGrease asked this question in Q&A
Discussion options

You must be logged in to vote

I think what author wants is @cast, but seems it is not perfect

---@class MyClassModified
---@field a integer
---@field b integer

---@class MyClass: MyClassModified
local MyClass = {}

---@return MyClass
function MyClass.new() end

function MyClass:finalize() end

---

local instance = MyClass.new()
instance.a = 4
instance.b = 5
instance:finalize()

---@cast instance MyClassModified
-- dont know why this line throws `cast-type-mismatch`
-- how come casting a child class to parent class not allowed ?

instance:finalize() --> Undefined field `finalize`, good
-- but it will still auto suggest `finalize`, so not perfect

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@tomlau10
Comment options

Answer selected by NickGrease
@NickGrease
Comment options

@tomlau10
Comment options

@NickGrease
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants