javascript - 得到错误`类型'{主题:主题;}' 在尝试将其作为道具传递给 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'.
我在这里做错了什么?
解决方案
弄清楚了。它应该是,
interface IFC {
theme: Theme
}
推荐阅读
- angular8 - Angular 8 差分加载并仅生成 ES5 包
- asp.net-mvc - 如何在 Ajax 发布后更新 Partial 视图
- sharepoint - 如何修改 Office365 Onenote 网页视图以隐藏导航面板
- android - ListView onClick 没有显示适配器到 CardView 详细信息
- ios - 尝试使用在 SafariViewController 中启动链接的 tableviewcells 快速创建选项卡式应用程序
- c# - asp.net mvc + angularJs中的模块注册问题
- css - 有没有办法让这个下拉菜单看起来像一个表格?
- c# - 枚举类型不再在 .Net core 3.0 FromBody 请求对象中工作
- java - 读取带有波兰语字母的 ANSI 文件并在没有口音的控制台中显示
- android - adb“连接的设备列表”为空,用于远程 Debian 虚拟机上的 USB 连接