Skip to content

Unable to override a getter when inheriting from a mixin classΒ #44938

Closed
@whzx5byb

Description

@whzx5byb

Bug Report

πŸ”Ž Search Terms

mixin getter override

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

class A {
    constructor(...args: any[]) {}
    get myName(): string { 
        return 'A'; 
    }
}

function Mixin<T extends typeof A>(Super: T) {
    return class B extends Super {
        get myName(): string {
            return 'B';
        }
    }
}

class C extends Mixin(A) {
    get myName(): string { 
    // Unexpected Error:
    // 'myName' is defined as a property in class 'Mixin<typeof A>.B & A', but is overridden here in 'C' as an accessor.
        return 'C' 
    }
}

var c = new C();
console.log(c.myName); // will print 'C' as expected though

πŸ™ Actual behavior

Error in get myName() of class C:
'myName' is defined as a property in class 'Mixin<typeof A>.B & A', but is overridden here in 'C' as an accessor.

It is obviously incorrect because myName is defined as a getter (NOT a property) in either A or B.

πŸ™‚ Expected behavior

No error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions