![](/img/trans.png)
[英]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.