I'm trying to add types to a class which extends "this" in the constructor.
I saw this question Typescript: extending "this" inside class but I don't know in advance which object would passed to the constructor.
class Baz<T extends object> {
public test;
constructor(props: T) {
Object.assign(this, props);
}
}
interface IFoo {
foo: number;
}
const p = new Baz<IFoo>({foo: 1});
p.test;
p.foo; // Not recognized.
I'm trying to recognize as properties the fields passed as object.
test.testwasn't really relevant... It was there just to show that I can access to the property of the class (of course) but not the one assigned in the constructor (foo)