I need to preserve column types and column id has to be either string or keyof data. Spent few hours, cant make it work. I would be glad for any help.
date: string;
}
type ColumnId<T> = keyof T | (string & {});
type BaseColumn<T> = {
id: ColumnId<T>;
title: string;
}
const columns2: BaseColumn<DataRow>[] = [
{
id: 'checkbox',
title: 'Id',
},
{
id: 'date',
title: 'ID',
},
]
class TestClass<T, C extends BaseColumn<T> = BaseColumn<T>> {
data: T[] = []
columns: C[] = []
constructor(data: T[], columns: C[]) {
this.data = data;
this.columns = columns;
}
}
const test = new TestClass<DataRow>([], columns2);
for (const column of test.columns) {
// just data types showing, no custom checkbox type checking
if (column.id === '') {
console.log('This is a checkbox column');
} else {
console.log(`This is a ${column.id} column`);
}
}```