Reactjs 使用TypeScript响应组件子级错误
几天前我开始学习react with typescript,我发现了这个错误Reactjs 使用TypeScript响应组件子级错误,reactjs,typescript,Reactjs,Typescript,几天前我开始学习react with typescript,我发现了这个错误 /home/sotiris/Github/ecommerce-merng-platform/admin/src/components/DashboardHOC/DashboardHOC.tsx TypeScript error in /home/sotiris/Github/ecommerce-merng-platform/admin/src/components/DashboardHOC/DashboardH
/home/sotiris/Github/ecommerce-merng-platform/admin/src/components/DashboardHOC/DashboardHOC.tsx
TypeScript error in /home/sotiris/Github/ecommerce-merng-platform/admin/src/components/DashboardHOC/DashboardHOC.tsx(118,22):
No overload matches this call.
Overload 1 of 2, '(props: { component: ElementType<any>; } & { children: string | number | boolean | {} | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | ReactNodeArray | ReactPortal; disableGutters?: boolean | undefined; fixed?: boolean | undefined; maxWidth?: false | ... 5 more ... | undefined; } & CommonProps<...> & Pick<...>): Element', gave the following error.
Type 'ReactNode' is not assignable to type 'string | number | boolean | {} | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | ReactNodeArray | ReactPortal'.
Type 'undefined' is not assignable to type 'string | number | boolean | {} | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | ReactNodeArray | ReactPortal'.
Overload 2 of 2, '(props: DefaultComponentProps<ContainerTypeMap<{}, "div">>): Element', gave the following error.
Type 'ReactNode' is not assignable to type 'string | number | boolean | {} | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | ReactNodeArray | ReactPortal'.
Type 'undefined' is not assignable to type 'string | number | boolean | {} | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | ReactNodeArray | ReactPortal'. TS2769
116 | <main className={classes.content}>
117 | <ErrorAlert>
> 118 | <Container>{children}</Container>
| ^
119 | </ErrorAlert>
120 | </main>
121 | </div>
/home/sotiris/Github/ecommerce-merng-platform/admin/src/components/DashboardHOC/DashboardHOC.tsx
/home/sotiris/Github/ecommerce-merng-platform/admin/src/components/DashboardHOC/DashboardHOC.tsx中的类型脚本错误(118,22):
没有与此调用匹配的重载。
重载1/2'(props:{component:ElementType;}&{children:string | number | boolean |{}ReactElement ReactElement component)>| null)|(new(props:any)=>component)>| ReactNodeArray | ReactPortal;disableGutters?:boolean |未定义;fixed?:boolean |未定义;maxWidth?:false |…5更多…|未定义;}&CommonProps&Pick):元素',出现以下错误。
类型“ReactNode”不可分配给类型“string | number | boolean |{}| ReactElement ReactElement Component)>| null)|(新建(props:any)=>Component)>| ReactNodeArray | ReactPortal”。
类型“undefined”不可分配给类型“string | number | boolean |{}| ReactElement ReactElement Component)>| null)|(新建(props:any)=>Component)>| ReactNodeArray | ReactPortal”。
重载2/2'(props:DefaultComponentProps):元素',导致以下错误。
类型“ReactNode”不可分配给类型“string | number | boolean |{}| ReactElement ReactElement Component)>| null)|(新建(props:any)=>Component)>| ReactNodeArray | ReactPortal”。
类型“undefined”不可分配给类型“string | number | boolean |{}| ReactElement ReactElement Component)>| null)|(新建(props:any)=>Component)>| ReactNodeArray | ReactPortal”。TS2769
116 |
117 |
>118{儿童}
| ^
119 |
120 |
121 |
Dashboard.tsx
const DashboardHOC: React.FC<React.ReactNode> = ({ children }) => {
...
{children}
...
}
const DashboardHOC:React.FC=({children})=>{
...
{儿童}
...
}
Error.tsx
const Error: React.FC<React.ReactNode> = ({ children }) => {
...
{children}
...
}
const错误:React.FC=({children})=>{
...
{儿童}
...
}
我做错了什么
React.FC<React.ReactNode>
或者,如果您更愿意明确表示没有其他道具:
const DashboardHOC: React.FC<{}> = ({ children }) => {
const DashboardHOC:React.FC=({children})=>{
const DashboardHOC: React.FC<{}> = ({ children }) => {