Skip to content

Be confused to Backticks #2949

Open
Open
@ChouUn

Description

@ChouUn

Issue Description

I noticed two examples about backticks.
The first is in @generic Capture with Backticks

---@class Vehicle
local Vehicle = {}
function Vehicle:drive() end

---@generic T
---@param class `T` # the type is captured using `T`
---@return T       # generic type is returned
local function new(class) end

-- obj: Vehicle
local obj = new("Vehicle")

The second is in @param Generic Function Parameter

---@class Box

---@generic T
---@param objectID integer The ID of the object to set the type of
---@param type `T` The type of object to set
---@return `T` object The object as a Lua object
local function setObjectType(objectID, type) end

--> boxObject: Box
local boxObject = setObjectType(1, "Box")

Are there any differences between them?

---@return T
---@return `T`

Additional Notes

BTW, how can I annotate this:

---@class X
---@field A integer
---@field B string
---@field C boolean[]

---@param x X
---@param key string
---@return ?
function getter(x, key)
    return x[key]
end

Is it possible to use backticks?

Metadata

Metadata

Assignees

Labels

documentationHas to do with documentation either in the wiki or in the repo

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions