Below is a code snippet illustrating the issue at hand:
class Parent<T = unknown> {
constructor(private prop: T) {}
getProp(): T {
return this.prop;
}
}
class Child extends Parent {
constructor() {
super({
baba: 10,
bobo: 20
});
}
}
const instance = new Child();
const prop = instance.getProp();
// |
// '-> prop is of type `unknown`
I am seeking a way for TypeScript to infer the type of the parent class based on the object value, without explicitly specifying the type.
In this scenario, the desired result would be
Parent<{baba: number, bobo: number}>
Is such automatic inference achievable?