Consider the following scenario:
class Datum {}
An error message (
error TS2304: Cannot find name 'T'
) is encountered when attempting the following:
class Data<T extends Datum> {
datum: T
constructor() {
this.datum = new T()
}
}
Subsequently, an attempt is made which results in another error message (
Type 'Datum' is not assignable to type 'T'
):
class Data<T extends Datum> {
datum: T
constructor() {
this.datum = new Datum();
}
}
Query: Is it impossible to create instances of the constrained types like T? The expectation was that since T is restricted to extend Datum
, assigning datum: T = new Datum()
should be feasible.