Is there a way to define a type for "any class that implements this abstract class"?
For instance:
// LIBRARY CODE
abstract class Table {
static readonly tableName: string;
}
type TableConstructor = typeof Table;
// type TableConstructor = (new (...args: never) => Table);
const createORM = (tables: Array<TableConstructor>) => {
return {
executeQuery() {
// What should be the type of the "tables" array
// to accommodate both of the following two lines
console.log(tables[0].tableName)
return new tables[0]();
// ~~~~~~~~~~~~~~~~
// Cannot instantiate an abstract class
}
}
}
// EXAMPLE USER CODE
class Foo implements Table {
static get tableName() {
return 'foo';
}
}
const orm = createORM([Foo]);