Why doesn't the constructor signature match the interface declaration in the following excerpt and how should I re-express it? The reported error is
'Class 'Item' incorrectly implements interface 'ItemClass'. Type 'Item' provides no match for the signature 'new (Scope?: Scope | undefined): Item'.'
The point of this code is factory support for subclasses identified at run-time by a string name coming from a serialisation of the class. The abstract AsyncCtor defines and initialises a Ready property. I could do 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 stop declaring the fact that Item implements ItemClass, everything compiles and the Item.new(raw) method works fine, so obviously it actually does implement ItemClass.
Before anyone suggests it, I've already tried
constructor(public Scope?: Scope | undefined) {