【问题标题】:Cannot assign theme in React无法在 React 中分配主题
【发布时间】:2022-10-08 10:45:32
【问题描述】:

我需要编译 UniswapV2 fork,但它不想编译。错误如下。

/src/components/AccountDetails/index.tsx(230,28) 中的 TypeScript 错误: 'import("/node_modules/@types/react-redux/node_modules/@types/react/index").Context<import("/node_modules/@types/styled-components/index").DefaultTheme>' 类型的参数不能分配给“React.Context<import("/node_modules/@types/styled-components/index").DefaultTheme>' 类型的参数。 TS2345

        228 | }: AccountDetailsProps) {
        229 |   const { chainId, account, connector } = useActiveWeb3React()
      > 230 |   const theme = useContext(ThemeContext)
            |                            ^
        231 |   const dispatch = useDispatch<AppDispatch>()
        232 | 
        233 |   function formatConnectorName() {

主题上下文定义如下:

export const ThemeContext: React.Context<AnyIfEmpty<DefaultTheme>>;

【问题讨论】:

    标签: javascript reactjs typescript uniswap


    【解决方案1】:

    同样的错误。 ThemeContext 和 styled-components 之间似乎存在兼容问题。

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    【解决方案2】:

    你找到答案了吗?我遇到了同样的问题,当我将打字稿版本从 3.8.3 更新到 4.8.3 时,我开始遇到同样的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-08
      • 1970-01-01
      • 2020-01-07
      • 1970-01-01
      • 2017-02-19
      • 2023-02-17
      相关资源
      最近更新 更多