【发布时间】:2019-07-08 23:19:06
【问题描述】:
我刚刚被这个击中了。
原来在文件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/react-select 2.0.17 非常相似的东西(请参阅我的另一篇文章)。能够通过降级到较低版本(2.0.8)来解决这个问题。通过反复试验。然而,react-select 依赖于@types/react-transition-group(在版本“*”),现在卡住了这个错误。
标签: reactjs typescript typescript-typings react-transition-group