From 267b74b2566c0ca4e81d3414f117fdb35fe0f7a1 Mon Sep 17 00:00:00 2001 From: Koutaro Chikuba Date: Sun, 5 Feb 2017 19:39:51 +0900 Subject: [PATCH] Add next.js flowtype definition to with-flow example (#973) * Add next.js flowtype definition to with-flow * Add render api types for flow * Add prefetch types * Fix push/replace api types to promise --- examples/with-flow/.flowconfig | 1 + examples/with-flow/types/next.js.flow | 50 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 examples/with-flow/types/next.js.flow diff --git a/examples/with-flow/.flowconfig b/examples/with-flow/.flowconfig index 4a58bdcdef3eb..4dc0652c71d5d 100644 --- a/examples/with-flow/.flowconfig +++ b/examples/with-flow/.flowconfig @@ -3,5 +3,6 @@ [include] [libs] +types/ [options] diff --git a/examples/with-flow/types/next.js.flow b/examples/with-flow/types/next.js.flow new file mode 100644 index 0000000000000..b4a0b851f2ea8 --- /dev/null +++ b/examples/with-flow/types/next.js.flow @@ -0,0 +1,50 @@ +/* @flow */ + +declare module "next" { + declare type NextApp = { + prepare(): Promise; + getRequestHandler(): any; + render(req: any, res: any, pathname: string, query: any): any; + renderToHTML(req: any, res: any, pathname: string, query: string): string; + renderError(err: Error, req: any, res: any, pathname: any, query: any): any; + renderErrorToHTML(err: Error, req: any, res: any, pathname: string, query: any): string; + }; + declare module.exports: (...opts: any) => NextApp +} + +declare module "next/head" { + declare module.exports: Class>; +} + +declare module "next/link" { + declare module.exports: Class>; +} + +declare module "next/prefetch" { + declare export var prefetch: (url: string) => any; + declare export var reloadIfPrefetched: any; + declare export default Class>; +} + +declare module "next/router" { + declare module.exports: { + route: string; + pathname: string; + query: Object; + onRouteChangeStart: ?((url: string) => void); + onRouteChangeComplete: ?((url: string) => void); + onRouteChangeError: ?((err: Error & {cancelled: boolean}, url: string) => void); + push(url: string, as: ?string): Promise; + replace(url: string, as: ?string): Promise; + }; +} + +declare module "next/document" { + declare export var Head: Class>; + declare export var Main: Class>; + declare export var NextScript: Class>; + declare export default Class> & { + getInitialProps: (ctx: {pathname: string, query: any, req?: any, res?: any, xhr?: any, err?: any}) => Promise; + renderPage(cb: Function): void; + }; +}