我正在尝试asyncComponent使用TypeScript 创建一个更高阶的组件,但不能完全正确地获得类型.
从本质上讲,这适用于JS与webpack ...
const Auth = asyncComponent(() =>
require.ensure([], require => require("../auth/index").default, "auth_async"),
);
Run Code Online (Sandbox Code Playgroud)
我asyncComponent是一个更高阶的函数,执行以下操作...
import * as React from "react";
import { Component } from 'react';
export interface IAsyncComponentProps {}
export interface IAsyncComponentState {
Component: typeof Component
}
interface IGetComponent {
(): Promise<typeof Component>;
}
export default function asyncComponent (getComponent: IGetComponent) {
let ComponentCache: typeof Component = null;
return class AsyncComponent extends Component<IAsyncComponentProps, IAsyncComponentState> {
state: {
Component: typeof Component,
};
constructor(props: IAsyncComponentProps) { …Run Code Online (Sandbox Code Playgroud)