Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be confused to Backticks #2949

Open
ChouUn opened this issue Nov 11, 2024 · 11 comments
Open

Be confused to Backticks #2949

ChouUn opened this issue Nov 11, 2024 · 11 comments
Assignees
Labels
documentation Has to do with documentation either in the wiki or in the repo

Comments

@ChouUn
Copy link

ChouUn commented Nov 11, 2024

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?

@ChouUn ChouUn added the documentation Has to do with documentation either in the wiki or in the repo label Nov 11, 2024
@ChouUn ChouUn changed the title Confused with Backticks Be confused to Backticks Nov 11, 2024
@CppCXY
Copy link
Collaborator

CppCXY commented Nov 11, 2024

应该没有区别

@Issues-translate-bot
Copy link

Sumneko Lua translate bot


There should be no difference

@ChouUn
Copy link
Author

ChouUn commented Nov 11, 2024

应该没有区别

I guess so too XD
我猜也是 XD
I think it would be best to unify the usage, to reduce unnecessary ambiguity.
感觉最好能统一一下用法,减少不必要的歧义。
And it seems there is no good solution for the Additional Notes part?
另外 Additional 部分感觉一直没有很好的解决方式?

@CppCXY
Copy link
Collaborator

CppCXY commented Nov 11, 2024

应该没有区别

I guess so too XD 我猜也是 XD I think it would be best to unify the usage, to reduce unnecessary ambiguity. 感觉最好能统一一下用法,减少不必要的歧义。 And it seems there is no good solution for the Additional Notes part? 另外 Additional 部分感觉一直没有很好的解决方式?

additional部分是什么意思

@ChouUn
Copy link
Author

ChouUn commented Nov 11, 2024

additional部分是什么意思

In the Additional Notes section of the body, what should the ---@return ? look like?
Issue 正文中的 Additional Notes 那一节,请问 ---@return ? 部分应该怎么填

@CppCXY
Copy link
Collaborator

CppCXY commented Nov 11, 2024

不过以后应该会出现类似:

---@param a `T`
---@return System.`T` 

这样的类型变换功能,

你要的功能在typescript里面叫做Indexed type, 这个实现看起来比较复杂如果实现了的话, 他有可能是:

---@param key `T`
---@return X[`T`]

@Issues-translate-bot
Copy link

Sumneko Lua translate bot


However, something like this should appear in the future:

---@param a `T`
---@return System.`T`

Such type conversion function,

The function you want is called Indexed type in typescript. This implementation looks more complicated. If implemented, it may be:

---@param key `T`
---@return X[`T`]

@ChouUn
Copy link
Author

ChouUn commented Nov 11, 2024

你要的功能在typescript里面叫做Indexed type

I am indeed an old user of Typescript, so asked this question.
我确实是 ts 的老用户,所以有此一问。
I think it is an important feature for annotations.
感觉还是比较重要的特性。

@CppCXY
Copy link
Collaborator

CppCXY commented Nov 11, 2024

ts里面提供的类型体操要实现起来是比较麻烦的, 我看这一套体操, mapped type, indexed type, keyof type, extends type, 都要实现才能满足基本需求, luals在4.0有非常初步的泛型类支持, 那时候再讨论这些或许才有意义

@Issues-translate-bot
Copy link

Sumneko Lua translate bot


The type gymnastics provided in ts are more troublesome to implement. I think this set of gymnastics, mapped type, indexed type, keyof type, extends type, must be implemented to meet the basic needs. Luals has very preliminary generics in 4.0 Class support, it might make sense to discuss these at that time

@ChrisKader
Copy link

I would like to contribute to 4.0 and implement these extended types but am unable to get it to build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Has to do with documentation either in the wiki or in the repo
Projects
None yet
Development

No branches or pull requests

5 participants