相关疑难解决方法(0)

将React.lazy与TypeScript一起使用

我试图在我的TypeScript React应用程序中使用React.lazy进行代码拆分。

我正在做的就是更改该行:

import {ScreensProductList} from "./screens/Products/List";
Run Code Online (Sandbox Code Playgroud)

到这行:

const ScreensProductList = lazy(() => import('./screens/Products/List'));
Run Code Online (Sandbox Code Playgroud)

但是该import('./screens/Products/List')部分会触发TypeScript错误,并指出:

Type error: Type 'Promise<typeof import("/Users/johannesklauss/Documents/Development/ay-coding-challenge/src/screens/Products/List")>' is not assignable to type 'Promise<{ default: ComponentType<any>; }>'.
  Property 'default' is missing in type 'typeof import("/Users/johannesklauss/Documents/Development/ay-coding-challenge/src/screens/Products/List")' but required in type '{ default: ComponentType<any>; }'.
Run Code Online (Sandbox Code Playgroud)

我不太确定我应该在这里做什么才能使其正常工作。

typescript reactjs

8
推荐指数
3
解决办法
2098
查看次数

React.lazy() 与 Typescript

我收到错误:

类型“Element”中缺少属性“default”,但类型“{default: ComponentType;”中需要属性“default” }'.ts(2322)

   {React.lazy(() => import(`../../i18n/locales/${this.props.lang}`).then(o => (
              <CustomSelects
                options={o.option}
                formattedMessageId="createroom_genre"
                value={this.props.genre}
                handleValueChange={this.handleGenreChange}
              />
            ))) }
Run Code Online (Sandbox Code Playgroud)

我阅读了Using React.lazy with TypeScript,但是,我不知道在我的情况下如何执行此操作。

如果您需要更多信息,请告诉我。谢谢。

typescript reactjs

3
推荐指数
1
解决办法
4836
查看次数

标签 统计

reactjs ×2

typescript ×2