简体   繁体   English

@ types / react-transition-group:通用类型&#39;ReactElement <P, T> &#39;需要1到2个类型参数.ts(2707)

[英]@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.

相关问题 类型 'React.ReactNode' 不可分配给类型 'import(".../@types/react-transition-group/node_modules/@types/react/index").ReactNode' - Type 'React.ReactNode' is not assignable to type 'import(".../@types/react-transition-group/node_modules/@types/react/index").ReactNode' 无法安装反应过渡组 - Can't install react-transition-group React.createElement问题:TS2322类型T不可分配给类型ReactElement &lt;{}&gt; - React.createElement issue: TS2322 Type T is not assignable to type ReactElement<{}> 尝试将 react-transition-group 实现到 react-router 中会产生错误:“元素类型无效......” - Trying to implement react-transition-group into react-router generates error : 'Element type is invalid ...' 模态上的反应过渡组 - react-transition-group on Modal React-transition-group Transition 在退出时不会触发动画 - React-transition-group Transition doesn't trigger animation on exit 尝试使用来自 react-transition-group 的 TransitionGroup、CSSTransition 时出现错误“元素类型无效......” - Error 'Element type is invalid …' when trying to use TransitionGroup, CSSTransition from react-transition-group 反应“反应过渡组”不起作用 - React “react-transition-group” doesn't work 无法解析 MUI IconButton 中的“react-transition-group” - Can't resolve 'react-transition-group' in MUI IconButton 无法解析 Primereact 下拉列表中的“react-transition-group” - Can't resolve 'react-transition-group' in primereact dropdown
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM