lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

[Question] Prefixing/modifying a generic to get a different class

Open Ketho opened this issue 3 years ago • 1 comments

In World of Warcraft we have a Frame class and a AceGUIFrame class, but the problem is they are created with CreateFrame("Frame") and AceGUI:Create("Frame") respectively.

How would I get AceGUI:Create("Frame") to return the AceGUIFrame class?

---@alias FrameType
---|"Frame"

---@class Frame
local Frame = {}
function Frame:SetToplevel(isTopLevel) end

---@generic T
---@param frameType `T` | FrameType
---@return T frame
function CreateFrame(frameType) end

local normalFrame = CreateFrame("Frame")
normalFrame:SetToplevel(true)
---@alias AceGUIContainerType
---|"Frame"

---@class AceGUIFrame
local AceGUIFrame = {}
function AceGUIFrame:SetTitle(text) end

local AceGUI = {}

---@generic T
---@param type `T` | AceGUIContainerType
---@return "AceGUI"..T
function AceGUI:Create(type) end

local aceguiFrame = AceGUI:Create("Frame")
aceguiFrame:SetTitle("Example")

Current behavior image

Expected behavior image

Original issue: https://github.com/Ketho/vscode-wow-api/pull/43

Ketho avatar Jul 11 '22 14:07 Ketho

Operations on types are currently not supported

sumneko avatar Jul 12 '22 06:07 sumneko