[英]Type 'React.ReactNode' is not assignable to type 'import(".../@types/react-transition-group/node_modules/@types/react/index").ReactNode'
[英]@types/react-transition-group: Generic type 'ReactElement<P, T>' requires between 1 and 2 type arguments.ts(2707)
我刚被这个击中。
原来在文件node_modules/@types/react-transition-group/TransitionGroup.d.ts
有这种类型:
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;
};
这会使编译失败并显示以下错误:
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.
我发现如果我替换掉它:
childFactory?(child: ReactElement): ReactElement;
为了这:
childFactory?(child: ReactElement<any, any>): ReactElement<any, any>;
但这不是真正的解决方案,也不是我认为的问题...
我该如何解决?
我遇到了同样的问题,并且@types/recompose
模块刚刚报告了一个非常相似的问题 。 作为临时修复,我卸载了@types/react-transition-group
并在项目的根目录中添加了types/react-transition-group.d.ts
文件,内容如下:
declare module 'react-transition-group' {
export const CSSTransitionGroup: any
}
至少您没有从node_modules
文件夹中更改内容。 我使用的是react-transition-group
v1,因此您的占位符定义可能看起来有些不同。 当然,您会放开所有您不提供的类型提示,因此,如果recompose
问题不相关,最好也给GitHub存储库一些提示,以便他们可以提供修复程序。
看起来此提交删除了所有模板值并导致中断。 我可以通过向软件包中明确添加版本(2.0.15)来解决此问题。
npm install @types/react-transition-group@2.0.15
2.0.15是最新的版本。 2.0.16及更高版本包含错误的提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.