DefinitelyTyped/types/next/document.d.ts
Ben Saufley 9a235d9000
[next] Elaborate on Document types
Adjust renderPage and Enhancer; add tests

Allows Enhancer to receive a React ComponentType that accepts one set of props and return a ComponentType that accepts a different set of props, the latter including at least url
2018-06-13 14:44:59 -04:00

55 lines
1.5 KiB
TypeScript

import * as React from "react";
import { NextContext } from ".";
export interface RenderPageResponse {
buildManifest: { [key: string]: any };
chunks: {
names: string[];
filenames: string[];
};
html?: string;
head: Array<React.ReactElement<any>>;
errorHtml: string;
}
export interface PageProps {
url: string;
}
export interface AnyPageProps extends PageProps {
[key: string]: any;
}
export type Enhancer<E extends PageProps = AnyPageProps, P extends any = E> = (page: React.ComponentType<P>) => React.ComponentType<E>;
/**
* Context object used inside `Document`
*/
export interface NextDocumentContext extends NextContext {
/** A callback that executes the actual React rendering logic (synchronously) */
renderPage<E extends PageProps = AnyPageProps, P extends any = E>(enhancer?: Enhancer<E, P>): RenderPageResponse; // tslint:disable-line:no-unnecessary-generics
}
export interface DocumentProps {
__NEXT_DATA__?: any;
dev?: boolean;
chunks?: {
names: string[];
filenames: string[];
};
html?: string;
head?: Array<React.ReactElement<any>>;
errorHtml?: string;
styles?: Array<React.ReactElement<any>>;
[key: string]: any;
}
export class Head extends React.Component<any> {}
export class Main extends React.Component {}
export class NextScript extends React.Component {}
export default class extends React.Component<DocumentProps> {
static getInitialProps(ctx: NextDocumentContext): Promise<DocumentProps> | DocumentProps;
}