检查 class 类型是否扩展了另一个 class?
Check if class type extends another class?
我很难表达我的问题,以下面这段代码为例。
class Foo {}
class Bar extends Foo {}
const myFct = (bar: typeof Bar) => {
if(bar instanceof Foo) {
// I want to check if Bar extends Foo
// bar is not an instance so instanceof won't do it
}
}
如何检查 class Bar 从 typeof 扩展 Foo?
试试这个:
class Foo {}
class Bar extends Foo {}
const myFct = (bar: typeof Bar) => {
if(bar.prototype instanceof Foo) {
// I want to check if Bar extends Foo
// bar is not an instance so instanceof won't do it
}
}
我很难表达我的问题,以下面这段代码为例。
class Foo {}
class Bar extends Foo {}
const myFct = (bar: typeof Bar) => {
if(bar instanceof Foo) {
// I want to check if Bar extends Foo
// bar is not an instance so instanceof won't do it
}
}
如何检查 class Bar 从 typeof 扩展 Foo?
试试这个:
class Foo {}
class Bar extends Foo {}
const myFct = (bar: typeof Bar) => {
if(bar.prototype instanceof Foo) {
// I want to check if Bar extends Foo
// bar is not an instance so instanceof won't do it
}
}