相关疑难解决方法(0)

使用webpack输入问题进行反应和打字

我正在尝试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)

typescript reactjs webpack

9
推荐指数
1
解决办法
1051
查看次数

标签 统计

reactjs ×1

typescript ×1

webpack ×1