typescript 类引用

标签 typescript inheritance

Flow 的概念是您可以编写以下类型定义来引用从另一个类继承的类: function getHouseClass(): Class<House> {}

这是指类,而不是类的实例。

Typescript 中有类似的概念吗? Class<House>显然在 TS 中不起作用。

谢谢!

最佳答案

我认为@toskv 是正确的。如果你看this两者之间的比较(在“访问类的类型”标题下方):

class Test {};
type TestType = Class<Test>;
// This should be equivalent to (if you can confirm, please send a PR):
type TestType = typeof Test;

typescript

class Test {};
type TestType = typeof Test;

下面应该是一样的:

function getHouseClass(): typeof House { return House; }

关于 typescript 类引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46110985/

相关文章:

typescript - Typescript 中的接口(interface)有什么区别?

c++ - 如何使用派生类中的函数而不将它们添加到基类中

c# - 获取接口(interface)但不是基础接口(interface)

c++ - sizeof(*this) 和结构继承

node.js - typescript 导入文件夹

typescript - 迁移到 angular2 RC4 路由

angular - 使用 Angular CLI/WebPack 汇总的可管道 RxJs 运算符的正确导入模式

javascript - Typescript: `let result: { [key: T[K]]: T } = {};` 不起作用,如何根据泛型键入我的对象?

java - 分层继承

python - 当我尝试向一个类添加参数时,我收到从另一个类继承的类的类型错误