' 需要 1 到 2 个类型的 arguments.ts(2707),reactjs,typescript,typescript-typings,react-transition-group"/>

首页 > 解决方案 > @types/react-transition-group:通用类型 'ReactElement' 需要 1 到 2 个类型的 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>;

但这不是真正的解决方案,或者我认为的问题......

我应该如何解决这个问题?

标签: reactjstypescripttypescript-typingsreact-transition-group

解决方案


看起来此提交删除了所有模板值并导致中断。我能够通过向包中显式添加版本(2.0.15)来解决此问题。

npm install @types/react-transition-group@2.0.15

2.0.15 是最新的。2.0.16 和更新版本包含错误提交。


推荐阅读