Lua's variables can act as C#-like properties by setting `__newindex` appropriately. Getters and setters occasionally have different type signatures. However, the `@field` annotation can only represent one type. ```lua -- hoge.meta.lua ---@meta ---@class Point ---@field x number ---@field y number Point = {} ---@class Hoge ---@field position Point ⚠️ actually a property Hoge = {} ---@return Hoge function new_hoge() end ``` ```lua -- main.lua local hoge = new_hoge() hoge.position = { 3, 7 } -- emits "Missing required fields in type `Point`: `x`, `y`" print(hoge.position.x) -- 3.0 print(hoge.position.y) -- 7.0 ``` (Full sample program is [here](https://codeberg.org/haruomaki/luaproperty)) It should be annotated as "`position`'s setter receives a `table<number, number>`, and its getter returns a `Point`." How about adding a new syntax to describe this?
Activity
tomlau10 commentedon Sep 28, 2024
This seems like a duplicated feature request as #1298, which requesting support for setting / getting the same field with different types.