What is the reason for the discrepancy between the constructor signature and interface declaration in the code snippet below, and how can it be rephrased? The reported error is
'Class 'Item' incorrectly implements interface 'ItemClass'. Type 'Item' provides no match for the signature 'new (Scope?: Scope | undefined): Item'.'
The purpose of this code is to provide factory support for subclasses identified at runtime by a string name obtained from a class serialization. The abstract AsyncCtor defines and initializes a Ready property. I could achieve this directly in
export interface ItemClass {
Ready: Promise<any>;
new(Scope?: Scope): Item;
}
export abstract class AsyncCtor {
public Ready: Promise<any> = new Promise((resolve, reject) => resolve(undefined));
}
export abstract class Item extends AsyncCtor implements ItemClass {
static Type: Map<string, ItemClass> = new Map<string, ItemClass>();
static register(typeName: string, typeClass: ItemClass): void {
this.Type.set(typeName, typeClass);
}
public static new(raw: any): Item {
let graph = typeof raw === "string" ? JSON.parse(raw) : raw;
let typeClass = Item.Type.get(graph.Type) as ItemClass;
let item = new typeClass();
...
return item;
}
constructor(public Scope?: Scope) {
super();
}
}
If I remove the explicit declaration that Item implements ItemClass, everything compiles successfully and the Item.new(raw) method functions properly, indicating that it does indeed implement ItemClass.
Despite trying
constructor(public Scope?: Scope | undefined) {