I'm troubleshooting an issue with my code:
class Base<T> {}
class Test {
prop: Base<any>;
createProp<T>() {
this.prop = new Base<T>();
}
}
const test = new Test();
test.createProp<{ a: number }>();
test.prop // Base<any> expected Base<{ a: number }>
After calling the createProp
method with the generic parameter, the type of the prop
property should be updated to the new type. However, currently, it remains as Base<any>
. Is there a way to achieve this using TypeScript?