我在将 React lazy 与我使用 TypeScript 和 Redux 的项目相结合时遇到了问题。这是我的代码:
// lazy-area.tsx
const LazyArea = ({text}: Props): JSX.Element => {
....
};
export const LazyArea = connect(
mapStateToProps,
mapDispatchToProps
)(LazyArea);
//Menu.tsx
import React, { lazy, Suspense } from 'react';
....
const lazyArea = lazy(() => import('./lazy-area'));
const Menu = ({
.....
}: Props): JSX.Element | null => {
return (
<Suspense fallback={LoadingView}>
<LazyArea />
</Suspense>
)
export const Menu = connect(
mapStateToProps,
mapDispatchToProps
)(Menu);
});
Run Code Online (Sandbox Code Playgroud)
通过此设置,我收到一条错误消息:
Type 'Promise<typeof import("/home/user/app/lazy-area")>' is not assignable …Run Code Online (Sandbox Code Playgroud)