My code is this:
export interface TreeItem {
id: string;
children: this[];
collapsed?: boolean;
}
const createTreeItem = <T extends TreeItem>(): T => {
return {
id: 'root',
children: []
}
}
But I get an error on the return type of createTreeItem which is the following:
TS2322: Type '{ id: string; children: never[]; }' is not assignable to type 'T'. '{ id: string; children: never[]; }' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'TreeItem'.
I have absolutely no idea what does this mean.