【发布时间】:2022-01-19 23:46:21
【问题描述】:
我很难表达我的问题,以下面的代码为例。
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
}
}
如何从 typeof 检查类 Bar extends Foo ?
【问题讨论】:
-
Object.getPrototypeOf? -
这能回答你的问题吗? stackoverflow.com/questions/14486110/…
-
@JafarJabr 就是这样,谢谢!
-
Object.getPrototypeOf(Bar) === Foo
标签: javascript typescript instanceof typeof