I'm attempting to create a generic table builder class. Within the table builder, I define an anonymous class which stores column definitions. I would like the table builder to store instances of these definitions in an array. Here is the simplified class definition I'm currently working with:
export class TableBuilder<T> {
Column = class {
constructor(public data: T) {}
}
private columns: Array<TableBuilder['Column']>
column(data: T) {
const col = new this.Column(data);
this.columns.push(col);
}
}
The line this.columns.push(col) throws a compile-time error: Argument of type '(anonymous class)' is not assignable to parameter of type 'typeof (anonymous class)'
Is there a way to define the columns member as an array of anonymous class instances? I can define it as type any[], but I would prefer a solution that preserves type enforcement of column entries.