What is causing this code to fail?
interface ISomeData {
name: string;
}
class SomeData implements ISomeData {
name: string = "adam";
}
class SomeClass<T extends ISomeData> {
constructor(dataTemplate?: T) {
this.dataTemplateInternal = dataTemplate;
}
private dataTemplateInternal: T;
public initSomeData() : T {
let data: T = new SomeData();
if (this.dataTemplateInternal) {
return this.dataTemplateInternal;
}
return data;
}
}
The first line of "initSomeData" has an error saying
Type 'SomeData' is not assignable to type 'T'
But since my generic constraint is based on an interface, which SomeData implements, shouldn't that be sufficient?
Ridiculously long link to this code in the TypeScript Playground