this can't be used in this way. Let me suggest a code to achieve what you want.
class A {
get projections() {
// ...
let result = {}; // <-- your return object
return (<T>(obj: T): { [id: string]: T } => result)(this);
}
}
class B extends A {}
new B().projections // => { [id: string]: B }
I'd not like to use the anonymous function but this was the way I found to get your result.
You can create a private help function on A to make the code more readable:
class A {
private applyResult<T>(obj: T, result: { [id: string]: T }) {
return result;
}
get projections() {
// ...
let result = {}; // <-- your return object
return this.applyResult(this, result);
}
}
class B extends A {}
new B().projections // => { [id: string]: B }
I hope this helps in some way.
thisrefers to a specific instance of an object, not a class itself. That's why it doesn't work.