收到错误的`Type'{theme:Theme; }'在尝试将其作为道具传递给App组件时无法分配给类型`

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了收到错误的`Type'{theme:Theme; }'在尝试将其作为道具传递给App组件时无法分配给类型`相关的知识,希望对你有一定的参考价值。

就我的应用程序启动而言,我采用的方法略有不同,因为我想在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

以上是关于收到错误的`Type'{theme:Theme; }'在尝试将其作为道具传递给App组件时无法分配给类型`的主要内容,如果未能解决你的问题,请参考以下文章

Element 'beans' cannot have character [children],because the type's content type is elem

Java,AWTUtilities,eclipse报编译错误:Access restriction: The type 'AWTUtilities' is not API (restr

No resource found that matches the given name 'Theme.AppCompat.Light'

No context type was found in the assembly 'xxx.xxxx'. CodeFirst Ef错误

错误记录Flutter 编译报错 ( The parameter ‘‘ can‘t have a value of ‘null‘ because of its type, but the im )(代

创建android项目时,出现No resource found that matches the given name 'Theme.AppCompat.Light'