【发布时间】:2019-08-15 12:45:17
【问题描述】:
对于 NextJS 应用程序,我想创建一个 App (_app.tsx) 类增强器,但我无法让它工作以调用传递的基础应用程序类的静态方法。
interface Constructor<T> {
new (...args: any[]): T;
prototype: T;
}
class MockNextApp<P={}>{
props: P;
static getInitialProps = (ctx: {}) => {foo:"bar"}
constructor(props: P) {
this.props = props;
}
}
function enhanceApp<T extends Constructor<MockNextApp>>(Base: T) {
return class extends Base{
static getInitialProps = (ctx: {}) => {
return Base.getInitialProps();
}
}
}
打字稿错误:
Property 'getInitialProps' does not exist on type 'T'.
您可以查看示例here。
【问题讨论】:
标签: typescript next.js