My TypeScript code includes some generic classes:
type UserId = number
type Primitive = string | number | boolean
class ColumnValue<T, S extends Primitive> {
constructor(public columnName: String, public value: S) { }
}
abstract class Column<T> {
constructor(public columnName: String) { }
public set<S extends Primitive>(value: T): ColumnValue<T, S> {
return new ColumnValue(this.columnName, this.getValue(value))
}
public abstract getValue<S extends Primitive>(value: T): S
}
let id = new class extends Column<UserId> {
constructor() { super("id") }
public getValue(value: UserId): number {
return value
}
}()
However, I'm encountering an error that reads:
Class '(Anonymous class)' incorrectly extends base class 'Column<number>'.
Types of property 'getValue' are incompatible.
Type '(value: number) => number' is not assignable to type '<S extends Primitive>(value: number) => S'.
Type 'number' is not assignable to type 'S'