[英]@types/react-transition-group: Generic type 'ReactElement<P, T>' requires between 1 and 2 type arguments.ts(2707)
I've just got hit with this one. 我刚被这个击中。
Turns out that in the file node_modules/@types/react-transition-group/TransitionGroup.d.ts
原来在文件
node_modules/@types/react-transition-group/TransitionGroup.d.ts
There is this type: 有这种类型:
type TransitionGroupProps<T extends keyof JSX.IntrinsicElements = "div", V extends ReactType = any> =
(IntrinsicTransitionGroupProps<T> & JSX.IntrinsicElements[T]) | (ComponentTransitionGroupProps<V>) & {
children?: ReactElement<TransitionProps> | Array<ReactElement<TransitionProps>>;
childFactory?(child: ReactElement): ReactElement;
[prop: string]: any;
};
And this is making the compilation fail with this error: 这会使编译失败并显示以下错误:
ERROR in [at-loader] ./node_modules/@types/react-transition-group/TransitionGroup.d.ts:16:30
TS2707: Generic type 'ReactElement<P, T>' requires between 1 and 2 type arguments.
ERROR in [at-loader] ./node_modules/@types/react-transition-group/TransitionGroup.d.ts:16:45
TS2707: Generic type 'ReactElement<P, T>' requires between 1 and 2 type arguments.
I've found that if I replace this: 我发现如果我替换掉它:
childFactory?(child: ReactElement): ReactElement;
for this: 为了这:
childFactory?(child: ReactElement<any, any>): ReactElement<any, any>;
But this is not the real solution, or problem I think... 但这不是真正的解决方案,也不是我认为的问题...
How should I fix this? 我该如何解决?
I had the same problem, and there is an eerily similar issue reported just now for a @types/recompose
module. 我遇到了同样的问题,并且
@types/recompose
模块刚刚报告了一个非常相似的问题 。 As a temporary fix I uninstalled @types/react-transition-group
and added a types/react-transition-group.d.ts
file at the root of my project with the following: 作为临时修复,我卸载了
@types/react-transition-group
并在项目的根目录中添加了types/react-transition-group.d.ts
文件,内容如下:
declare module 'react-transition-group' {
export const CSSTransitionGroup: any
}
At least then you aren't changing stuff from the node_modules
folder. 至少您没有从
node_modules
文件夹中更改内容。 I'm using v1 of react-transition-group
so your placeholder definition might look a little different. 我使用的是
react-transition-group
v1,因此您的占位符定义可能看起来有些不同。 Of course you'll loose all type-hinting you don't provide yourself, so it might be and idea to give the GitHub repo a heads up as well so they can provide a fix, should the recompose
issue not be relevant. 当然,您会放开所有您不提供的类型提示,因此,如果
recompose
问题不相关,最好也给GitHub存储库一些提示,以便他们可以提供修复程序。
It looks like this commit removed all the template values and caused the break. 看起来此提交删除了所有模板值并导致中断。 I was able to resolve this by explicitly adding a version (2.0.15) to the package.
我可以通过向软件包中明确添加版本(2.0.15)来解决此问题。
npm install @types/react-transition-group@2.0.15
2.0.15 is the latest that works. 2.0.15是最新的版本。 2.0.16 and newer contains the bad commit.
2.0.16及更高版本包含错误的提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.