I am trying to create a type based on an abstract readonly string[]
in an abstract class. When I do so, two things happen:
- I get the error
'U' only refers to a type, but is being used as a value here.
- The value passed to the
column()
allows for any type of string
Here is an example in the playground.
What I want to happen, is for the array of strings to be converted to a union type for the parameter of the column()
method.
export abstract class Table {
abstract fields: readonly string[];
}
export class MyTable extends Table {
fields: readonly string[] = ['a', 'b', 'c'];
}
export class ResultSet<T, U extends Table> {
protected readonly _rows: T[] | T;
constructor(
rows: T[] | T,
readonly table: U,
) {
this._rows = rows;
}
column(name: (typeof U['fields'][number])) {
}
}
const set = new ResultSet([], new MyTable());
set.column('123'); // Should throw error