如何在Typescript中将函数的返回类型声明为类(而不是实例)

时间:2016-02-16 00:32:57

标签: typescript

我需要声明该函数返回一个类定义(而且是泛型的)。我怎么能这样做?

以下适用于非泛型类,但不适用于泛型:

export function composeAll(composeFunction: Function, depsFunction: Function):
(component: any) => typeof React.Component; // works

export function composeAll<V>(composeFunction: Function, depsFunction: Function):
(component: any) => typeof React.Component<V, {}>; // fails

由于

1 个答案:

答案 0 :(得分:0)

您不需要typeof。只是简单地

export function composeAll(composeFunction: Function, depsFunction: Function): 
    (component: any) => React.Component;

export function composeAll<V>(composeFunction: Function, depsFunction: Function): 
    (component: any) => React.Component<V, {}>;

您要做的事情被称为type query,我认为这不适用于此。