首页 > 解决方案 > 得到错误`类型'{主题:主题;}' 在尝试将其作为道具传递给 App 组件时不可分配给 type`

问题描述

就我的应用程序启动而言,我采用了稍微不同的方法,因为我想在我的组件中使用useLocation钩子。App我对 Typescript 有点陌生,我遇到了一个问题。这是我所拥有的:

// index.tsx

const theme: Theme = createMuiTheme({
  palette: {
    primary: {
      main: '#43C099',
    },
  },
});

ReactDOM.render(
  <Provider store={store}>
    <ThemeProvider theme={theme}>
      <CssBaseline />
          <Router>
            <App theme={theme} />
          </Router>
    </ThemeProvider>
  </Provider>
, document.getElementById('root'));
// App.tsx

interface IFC extends FC {
  theme: Theme
}

const App: FC<IFC> = ({ theme }) => {

// ...

错误来自index.tsx,我的 IDE 下划线<App ...并抛出错误,

Type '{ theme: Theme; }' is not assignable to type 'IFC'.

我在这里做错了什么?

标签: javascriptreactjstypescript

解决方案


弄清楚了。它应该是,

interface IFC {
  theme: Theme
}

推荐阅读