Skip to content

the code in function can't run #2499

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

You must be logged in to vote

For the first case, we can use generics to return the correct type:

---@generic T
---@param type T
---@return T
function Get(type)
    return type
end
a = Get(_G)

For the second case, that kind of mutation can't really be annotated at the function, so we would have to @cast:

---@param name string
function Set(name)
    rawset(b,name,"test")
end

Set("test")
---@cast b {first: 1, name: string}

Replies: 1 comment 2 replies

Comment options

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

@carsakiller
Comment options

Answer selected by KeilAwk
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/type check Related to the type checking feature
2 participants