import { RouteProps, RouteComponentProps, match as Match, } from 'react-router-dom'; import { HelmetData } from 'react-helmet'; import { Request, Response } from 'express'; import { History, Location } from 'history'; import { Document as DefaultDoc } from './Document'; export interface CtxBase { req?: Request; res?: Response; history?: History; location?: Location; scrollToTop?: ScrollToTop; } export interface Ctx

extends CtxBase { match: Match

; } export interface AsyncComponent { getInitialProps: (props: Ctx) => any; load?: () => Promise; getChunkName: () => string | undefined; } export type AsyncRouteComponentType = React.ComponentType & AsyncComponent; /** * this type handles the component type in the route config object * { * path: "/", * exact: true, * component: ReactComponent <- AsyncRouteableComponent * } */ export type AsyncRouteableComponent = // re-exported from react-router (RouteComponentProps) | React.ComponentType> | React.ComponentType // After.js Page Component (getInitialProps and ...) | AsyncRouteComponentType> | AsyncRouteComponentType; export interface AsyncRouteComponentState { Component: AsyncRouteableComponent | null; } export interface AsyncRouteProps extends RouteProps { path?: string; Placeholder?: React.ComponentType; component: AsyncRouteableComponent; redirectTo?: string; } export type ScrollToTop = React.RefObject; // result of getInitalProps export type InitialData = Promise[]; export interface ServerAppState { afterData: AfterClientData; initialData: InitialData; } export interface InitialProps { match?: AsyncRouteProps; data: InitialData; } export interface AfterClientData { scrollToTop: ScrollToTop; ssg?: boolean; } // will send this object export interface ServerAppState { afterData: AfterClientData; initialData: InitialData; } // result of the render() export interface RenderResult { html: string; redirect: string; statusCode: number; data: InitialData; } // special result of getInitialProps export interface RedirectWithStatuCode { statusCode?: number; redirectTo?: string; } // renderApp() export interface AfterRenderAppOptions { req: Request; res: Response; assets: Assets; routes: AsyncRouteProps[]; document?: typeof DefaultDoc; chunks: Chunks; scrollToTop?: boolean; ssg?: boolean; customRenderer?: ( element: React.ReactElement ) => { html: string } | Promise<{ html: string }>; } // render() export type AfterRenderOptions = Omit, 'ssg'>; // renderStatic() export type AfterRenderStaticOptions = Omit, 'ssg'>; // Result of Document export interface RenderPageResult { html: string; helmet: HelmetData; } // TransitionBehavior export type TransitionBehavior = 'blocking' | 'instant'; // Document.js export interface DocumentgetInitialProps { req: Request; res: Response; helmet: HelmetData; assets: Assets; data: ServerAppState; renderPage: () => Promise; match: Match | null; scripts: string[]; styles: string[]; scrollToTop: ScrollToTop; } export type DocumentProps = Omit< DocumentgetInitialProps, 'req' | 'res' | 'renderPage' | 'scrollToTop' > & T; export type AfterContext = DocumentProps; // getAssets utility function export interface GetAssetsParams { chunks: Chunks; route?: AsyncRouteProps; } // ES Module type export type Module

= | { default?: P; [x: string]: any; } | { exports?: P; [x: string]: any; }; // assets.json that generated by razzle export interface Assets { [name: string]: { [ext: string]: string; }; } // chunks.json that generated by razzle export interface Chunks { [key: string]: { css: string[]; js: string[]; }; }