Skip to content

FR: Allow 'self' return type to allow return type changing with inheritance #1505

Open
@paul-reilly

Description

@paul-reilly

When annotating that one class has inherited from another, there is currently no way to annotate a function that returns it's current type that the current type should change when the class is inherited. Something along these lines, or something that accomplishes the same goal would be fantastic.

---@class Foo
Foo = {}

---@return self    --<-- 'self' refers to Foo so Foo.new() returns Foo
function Foo.new() end

---@class Bar : Foo
Bar = {}

local b = Bar.new() --<-- Bar.new() is inherited so the 'self' return type is now Bar
-- b should now be type Bar

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions