After successfully implementing the function isInstanceOfClass
, which determines if an instance is of a given class, I am now faced with the task of writing the correct typing for it.
class Parent {
isInstanceOfClass<T>(arg: T): this is T {
// implementation already exists
}
}
class FooClass extends Parent {
foo: number;
}
class BarClass extends Parent {
bar: number;
}
Here's an example:
let foo: Parent;
if(foo.isInstanceOfClass(FooClass)) {
foo.foo = 1; // TS2339: Property 'foo' does not exist on type 'Parent & typeof FooClass'.
}
Is there anyone who can assist me in fixing this error?
Due to certain constraints, I am only able to modify the signature of the isInstanceOfClass
method and not the example code itself.