From 348feeddb160bcb40b9d96d446a0ec85c69d13cd Mon Sep 17 00:00:00 2001 From: mizchi Date: Fri, 3 Feb 2017 19:28:32 +0900 Subject: [PATCH 1/4] Add next.js flowtype definition to with-flow --- examples/with-flow/.flowconfig | 1 + examples/with-flow/types/next.js.flow | 41 +++++++++++++++++++++++++++ 2 files changed, 42 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..ec52095c136e2 --- /dev/null +++ b/examples/with-flow/types/next.js.flow @@ -0,0 +1,41 @@ +declare module "next" { + declare type NextApp = { + prepare(): Promise; + }; + 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 module.exports: 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): void; + replace(url: string, as: ?string): void; + }; +} + +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: any) => Promise; + renderPage(cb: Function): void; + }; +} From b191e9c78678aedb28ddf327e7354b7b7f81431e Mon Sep 17 00:00:00 2001 From: mizchi Date: Sun, 5 Feb 2017 17:18:12 +0900 Subject: [PATCH 2/4] Add render api types for flow --- examples/with-flow/types/next.js.flow | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/with-flow/types/next.js.flow b/examples/with-flow/types/next.js.flow index ec52095c136e2..86dc6607238ff 100644 --- a/examples/with-flow/types/next.js.flow +++ b/examples/with-flow/types/next.js.flow @@ -1,6 +1,13 @@ +/* @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 } @@ -35,7 +42,7 @@ declare module "next/document" { declare export var Main: Class>; declare export var NextScript: Class>; declare export default Class> & { - getInitialProps: (ctx: any) => Promise; + getInitialProps: (ctx: {pathname: string, query: any, req?: any, res?: any, xhr?: any, err?: any}) => Promise; renderPage(cb: Function): void; }; } From 5b8dea2073eb11a75fb098507e881e25e49192e2 Mon Sep 17 00:00:00 2001 From: mizchi Date: Sun, 5 Feb 2017 19:09:07 +0900 Subject: [PATCH 3/4] Add prefetch types --- examples/with-flow/types/next.js.flow | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/with-flow/types/next.js.flow b/examples/with-flow/types/next.js.flow index 86dc6607238ff..623041e3a0fcb 100644 --- a/examples/with-flow/types/next.js.flow +++ b/examples/with-flow/types/next.js.flow @@ -21,7 +21,9 @@ declare module "next/link" { } declare module "next/prefetch" { - declare module.exports: Class>; + declare export var prefetch: (url: string) => any; + declare export var reloadIfPrefetched: any; + declare export default Class>; } declare module "next/router" { From 4ada29c4ddb927029ee521ff921055a5cd96e9c4 Mon Sep 17 00:00:00 2001 From: mizchi Date: Sun, 5 Feb 2017 19:09:52 +0900 Subject: [PATCH 4/4] Fix push/replace api types to promise --- examples/with-flow/types/next.js.flow | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/with-flow/types/next.js.flow b/examples/with-flow/types/next.js.flow index 623041e3a0fcb..b4a0b851f2ea8 100644 --- a/examples/with-flow/types/next.js.flow +++ b/examples/with-flow/types/next.js.flow @@ -34,8 +34,8 @@ declare module "next/router" { onRouteChangeStart: ?((url: string) => void); onRouteChangeComplete: ?((url: string) => void); onRouteChangeError: ?((err: Error & {cancelled: boolean}, url: string) => void); - push(url: string, as: ?string): void; - replace(url: string, as: ?string): void; + push(url: string, as: ?string): Promise; + replace(url: string, as: ?string): Promise; }; }