【发布时间】:2018-04-08 00:54:11
【问题描述】:
我最近开始将我公司的一个项目的代码库迁移到 TypeScript,我在为这段代码添加类型注释时遇到了困难:
function factory( Base ) {
return class Extended extends Base {
...
}
}
const Extended = factory( React.Component );
const PureExtended = factory( React.PureComponent );
我试图用 TypeScript 来描述:
- 工厂只接受从 React.Component 类继承的类。
- 工厂返回继承自 React.Component 类的类。
我尝试了什么:
function factory( Base: React.Component<P, S> ): React.Component<P, S> {
return class Extended extends Base {
...
}
}
const Extended = factory( React.Component );
const PureExtended = factory( React.PureComponent );
这在类型检查上非常失败。
我正在使用:
- TypeScript 2.5.2
- Visual Studio 代码 1.16.1
- @types/react 16.0.14
【问题讨论】:
标签: javascript reactjs typescript