Well, I have implemented
isInstanceOfClass
class Parent {
isInstanceOfClass<T>(arg: T): this is T {
// already implemented
}
}
class FooClass extends Parent {
foo: number;
}
class BarClass extends Parent {
bar: number;
}
let foo: Parent;
if(foo.isInstanceOfClass(FooClass)) {
foo.foo = 1; // TS2339: Property 'foo' does not exist on type 'Parent & typeof FooClass'.
}
isInstanceOfClass
You're almost there!
It should be:
class Parent {
isInstanceOfClass<T>(arg: { new(): T }): this is T {
// already implemented
}
}
The difference is that what you're passing to isInstanceOfClass
is not the instance but the class.
Once you change it to be the class (constructor) then the error goes away.