Skip to content

Instantly share code, notes, and snippets.

@sheki
Created September 25, 2018 21:58
Show Gist options
  • Save sheki/6a5f0115935ffd1cb9c7a4e386bae912 to your computer and use it in GitHub Desktop.
Save sheki/6a5f0115935ffd1cb9c7a4e386bae912 to your computer and use it in GitHub Desktop.
declare module "react-loadable" {
declare type LoadingProps = {
isLoading: boolean,
pastDelay: boolean,
timedOut: boolean,
retry: () => void,
error: ?Error,
};
declare type CommonOptions = {
loading: React$ComponentType<LoadingProps>,
delay?: number,
timeout?: number,
modules?: Array<string>,
webpack?: () => Array<number>,
};
declare type OptionsWithoutRender<
TProps: {},
TComponent: React$ComponentType<TProps>
> = {
...CommonOptions,
loader(): Promise<TComponent | {default: TComponent}>,
};
declare type OptionsWithRender<
TProps: {},
TComponent: React$ComponentType<TProps>,
TModule
> = {
...CommonOptions,
loader(): Promise<TModule>,
render(loaded: TModule, props: React$ElementConfig<TComponent>): React$Node,
};
declare type Options<
TProps: {},
TComponent: React$ComponentType<TProps>,
TModule
> = OptionsWithoutRender<TComponent> | OptionsWithRender<TComponent, TModule>;
declare type MapOptions<
TProps: {},
TComponent: React$ComponentType<TProps>,
TModules: {[key: string]: *}
> = {
...CommonOptions,
loader: {
[key: $Keys<TModules>]: () => Promise<*>,
},
render(
loaded: TModules,
props: React$ElementConfig<TComponent>
): React$Node,
};
declare class LoadableComponent<TProps> extends React$Component<TProps> {
static preload(): Promise<void>;
}
declare type CaptureProps = {
report(moduleName: string): void,
};
declare module.exports: {
<TProps: {}, TComponent: React$ComponentType<TProps>, TModule>(
opts: Options<TProps, TComponent, TModule>
): Class<LoadableComponent<React$ElementConfig<TComponent>>>,
Map<TProps: {}, TComponent: React$ComponentType<TProps>, TModules>(
opts: MapOptions<TProps, TComponent, TModules>
): Class<LoadableComponent<React$ElementConfig<TComponent>>>,
Capture: React$ComponentType<CaptureProps>,
preloadAll(): Promise<void>,
preloadReady(): Promise<void>,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment