Improve types (#8097)

This commit is contained in:
Adam Misiorny 2019-07-25 04:48:38 +02:00 committed by Luis Fernando Alvarez D
parent 427a02a468
commit 55e87ea50c
3 changed files with 5 additions and 3 deletions

View file

@ -215,7 +215,7 @@ export async function loadGetInitialProps<
C extends BaseContext,
IP = {},
P = {}
>(Component: NextComponentType<C, IP, P>, ctx: C): Promise<IP | null> {
>(Component: NextComponentType<C, IP, P>, ctx: C): Promise<IP> {
if (process.env.NODE_ENV !== 'production') {
if (Component.prototype && Component.prototype.getInitialProps) {
const message = `"${getDisplayName(

View file

@ -112,7 +112,7 @@ function getRouter() {
export default singletonRouter as SingletonRouter
// Reexport the withRoute HOC
export { default as withRouter } from './with-router'
export { default as withRouter, WithRouterProps } from './with-router'
export function useRouter() {
return React.useContext(RouterContext)

View file

@ -38,7 +38,9 @@ declare module 'react' {
* `Page` type, use it as a guide to create `pages`.
*/
export type NextPage<P = {}, IP = P> = {
(props: P): JSX.Element
(props: P): JSX.Element | null
defaultProps?: Partial<P>
displayName?: string
/**
* Used for initial page load data population. Data returned from `getInitialProps` is serialized when server rendered.
* Make sure to return plain `Object` without using `Date`, `Map`, `Set`.