Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add next.js flowtype definition to with-flow example #973

Merged
merged 4 commits into from
Feb 5, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/with-flow/.flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
[include]

[libs]
types/

[options]
48 changes: 48 additions & 0 deletions examples/with-flow/types/next.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* @flow */

declare module "next" {
declare type NextApp = {
prepare(): Promise<void>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have some more public methods on app.

  • app.render(req, res, pathname: string, query: any)
  • app.renderToHTML(req, res, pathname, query)
  • app.renderError(err, req, res, pathname, query)
  • app.renderErrorToHTML(err, req, res, pathname, query)

https://github.com/zeit/next.js/blob/master/server/index.js#L152

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nkzawa Thank you for your notice!
I wrote those types along with README.md and read codes a bit, but I lost them. (It looks not documented yet.) Anyway I add them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nkzawa
I added them and getRequestHandler for custom-handler. For https://github.com/zeit/next.js/blob/master/examples/custom-server/server.js#L7

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<React$Component<void, any, any>>;
}

declare module "next/link" {
declare module.exports: Class<React$Component<void, {href: string}, any>>;
}

declare module "next/prefetch" {
declare module.exports: Class<React$Component<void, {href: string, prefetch?: boolean}, any>>;
}

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;
Copy link
Contributor

@nkzawa nkzawa Feb 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I just noticed push and replace return Promise<boolean>. Others look good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

};
}

declare module "next/document" {
declare export var Head: Class<React$Component<void, any, any>>;
declare export var Main: Class<React$Component<void, any, any>>;
declare export var NextScript: Class<React$Component<void, any, any>>;
declare export default Class<React$Component<void, any, any>> & {
getInitialProps: (ctx: {pathname: string, query: any, req?: any, res?: any, xhr?: any, err?: any}) => Promise<any>;
renderPage(cb: Function): void;
};
}