Skip to content

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

Closed as not planned
@Ketho

Description

@Ketho

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: Ketho/vscode-wow-api#43

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfeat/genericRelated to generic emulation feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions