缺少类型“Provider<AnyAction>”

Bye*_*oon 3 typescript reactjs redux

我正在用打字稿做反应项目。

这是我在 index.ts 中的代码

const store = configureStore(initialStateFromDB);
ReactDOM.render(
  <Provider store={store}>
    <App></App>
  </Provider>,
  document.getElementById('app')
);
Run Code Online (Sandbox Code Playgroud)

我犯了很多错误!

第一的。

Type 'Provider<AnyAction>' is missing the following properties from type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)>[]': length, pop, push, concat, and 25 more.ts(2345)
Run Code Online (Sandbox Code Playgroud)

第二

Conversion of type 'Store<{}, AnyAction> & { dispatch: {}; }' to type 'Provider<AnyAction>' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.ts(2352)
Run Code Online (Sandbox Code Playgroud)

我无法理解这些错误消息的含义。

我应该怎么做才能修复这个错误?

Bye*_*oon 7

我的天啊

我的文件名是 index.ts

我把它改成 index.tsx

现在运作良好。

  • 经过几个小时的挣扎后发现了这一点。谢谢。 (2认同)