更新时间:2023-10-11 08:27:52
您正在使用名为"app/actions/actions"
的模块.该模块实际上不是模块(属性映射),但是flux.createACtions(Actions)
的结果是什么:
You're using a module called "app/actions/actions"
. That module is actually not a module (a map of properties), but whatever's the result of flux.createACtions(Actions)
:
export = flux.createActions(Actions); // in actions.ts
那又返回什么?由于您没有为<T>
指定通用名称,并且由于createActions
的参数没有正确包含可以从中推断出的T
,因此假定T
只是{}
.这是在此处讨论,并最终被拒绝了.因此,如上所述,您需要指定泛型:
What does that return? Because you're not specifying the generic for <T>
, and because the params of createActions
don't correctly include a T
from which it could infer, it assumes that T
is just {}
. This was discussed here and ultimately declined. So, as mentioned, you need to specify the generic:
export = flux.createActions<Actions>(Actions);
但是要避免这种情况,您可以将本地(或远程)alt.d.ts
更改为:
But to avoid this, you could change your local (or remote) alt.d.ts
to be something like:
class Alt {
createActions<T extends ActionsClass>(con: ActionsClassConstructor<T>, ...): T;
}
type ActionsClassConstructor<T extends ActionsClass> = new (alt:Alt) => T;
这将根据您提供的构造函数添加正确推断所需的通用类型信息.
This adds the generic type info needed to correctly infer based on the constructor you supply.