EmmyLua / IntelliJ-EmmyLua

Lua IDE/Debugger Plugin for IntelliJ IDEA
https://emmylua.github.io
Apache License 2.0
1.73k stars 290 forks source link

[Question] How I make to show a value type from a table on a function in function #465

Closed ghost closed 2 years ago

ghost commented 2 years ago
--- @field value any
--- @class property
local property = {};

--- @generic T
--- @param value T
--- @param get fun(this: property): T
--- @return T
function Property(value, get)
    return {};
end

local value = Property(10, function(this)
    return this.value [[ How I make autocomplete to show 'value' and type number?]];
end);

Is possible to make it work?

CppCXY commented 2 years ago
---@class t
---@field value number
local t = {}

MakeProperty(t, "value")
print(t.value)
ghost commented 2 years ago

Yea but if I change the Property(false, ... is showing as number and not boolean. I searching for something to inherit de generic T from 'Property(value, get)' to 'get fun(this: property { value: T }): T' or something

CppCXY commented 2 years ago

Generics aren't as strong for the time being, and you can write comments

---@param this SpecialClass
local value = property(10, function (this)

end)
ghost commented 2 years ago
---@generic T
---@param value T
---@return { value: T }
function test(value)
    return { value = value }
end

local a2 = test(1);

a2.value [[is type T]]

Would be nice to have.