首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么:键入'React.ReactNode‘不能指定为..。ReactNode

为什么:键入'React.ReactNode‘不能指定为..。ReactNode
EN

Stack Overflow用户
提问于 2022-04-09 15:09:18
回答 1查看 1.6K关注 0票数 2

我有以下代码:

代码语言:javascript
复制
import axios from 'axios'
import type { NextPage } from 'next'
import type { AppProps } from 'next/app'
import { ReactElement, ReactNode, useEffect } from 'react'
import { Provider } from 'react-redux'
import Layout from '../components/Layout'
import { setAuthnRes } from '../slices/User'
import { store } from '../store'
import '../styles/globals.scss'
import { baseURL } from '../utils/baseURL'

type NextPageWithLayout = NextPage & {
    getLayout?: (page: ReactElement) => ReactNode
}

type AppPropsWithLayout = AppProps & {
    Component: NextPageWithLayout
}

axios.defaults.baseURL = baseURL(
    process.env.NEXT_PUBLIC_ENVIRONMENT ?? 'local',
    true
)

axios.defaults.withCredentials = true

function MyApp({ Component, pageProps }: AppPropsWithLayout) {
    const dispatch = store.dispatch
    const authnUserResp = store.getState().authnUser?.resp


    const getLayout = Component.getLayout ?? ((page) => <Layout>{page}</Layout>)

    return (
        <Provider store={store}>{getLayout(<Component {...pageProps} />)}</Provider> // <------ HERE
    )
}

export default MyApp

我明白了:

代码语言:javascript
复制
No overload matches this call.
  Overload 1 of 2, '(props: ProviderProps<AnyAction> | Readonly<ProviderProps<AnyAction>>): Provider<AnyAction>', gave the following error.
    Type 'React.ReactNode' is not assignable to type 'import("/Users/kukodajanos/Workspace/Tikex/Portal/Team/node_modules/@types/styled-jsx/node_modules/@types/react/index").ReactNode'.
      Type '{}' is not assignable to type 'ReactNode'.
  Overload 2 of 2, '(props: ProviderProps<AnyAction>, context: any): Provider<AnyAction>', gave the following error.
    Type 'React.ReactNode' is not assignable to type 'import("/Users/kukodajanos/Workspace/Tikex/Portal/Team/node_modules/@types/styled-jsx/node_modules/@types/react/index").ReactNode'.ts(2769)

在这一行:

代码语言:javascript
复制
<Provider store={store}>{getLayout(<Component {...pageProps} />)}</Provider>

我做了yarn cache clean

EN

回答 1

Stack Overflow用户

发布于 2022-09-16 11:23:41

只是为了突出显示解决方案,正如在问题评论中建议的那样:

只需删除node_modules文件夹和yarn.lockpackage-lock.json文件即可。在重新安装 deps之后。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71809262

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档