Skip to content

Can not override 'toString' method of a mix-in class #14439

@spacemeowx2

Description

@spacemeowx2

TypeScript Version: 2.2.1

Code

type Constructor<T> = new(...args: any[]) => T
function Tagged<T extends Constructor<{}>>(Base: T) {
  return class extends Base {
    _tag: string;
    constructor(...args: any[]) {
      super(...args)
      this._tag = ''
    }
  }
}

class A {
  toString () {
    return 'class A'
  }
}

class B extends Tagged(A) {
  // error TS2425
  toString () {
    return 'class B'
  }
}

class C extends A {
  toString () {
    return 'class C'
  }
}

Expected behavior:
No error.

Actual behavior:
error TS2425: Class 'Tagged.(Anonymous class) & A' defines instance member property 'toString'
, but extended class 'B' defines it as instance member function.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions