diff --git a/types/next/app.d.ts b/types/next/app.d.ts index aef2980063..eea2af428b 100644 --- a/types/next/app.d.ts +++ b/types/next/app.d.ts @@ -13,7 +13,7 @@ export type AppComponentContext = NextAppContext; * * @template Q Query object schema. */ -export interface NextAppContext { +export interface NextAppContext { Component: NextComponentType>; router: RouterProps; ctx: NextContext; @@ -25,7 +25,7 @@ export interface NextAppContext { * * @template Q Query object schema. */ -export interface AppProps { +export interface AppProps { Component: NextComponentType>; router: RouterProps; pageProps: any; @@ -41,6 +41,6 @@ export interface AppProps { export type AppComponentType = NextComponentType; export class Container extends React.Component {} -export default class App extends React.Component { - getInitialProps(context: C): Promise | IP; +export default class App

extends React.Component

{ + static getInitialProps(context: NextAppContext): Promise<{ pageProps: any }>; } diff --git a/types/next/document.d.ts b/types/next/document.d.ts index 2e9880db51..8296a8f136 100644 --- a/types/next/document.d.ts +++ b/types/next/document.d.ts @@ -30,7 +30,7 @@ export type Enhancer = ( * * @template Q Query object schema. */ -export interface NextDocumentContext extends NextContext { +export interface NextDocumentContext extends NextContext { /** A callback that executes the actual React rendering logic (synchronously) */ renderPage( enhancer?: Enhancer // tslint:disable-line no-unnecessary-generics @@ -86,8 +86,6 @@ export type DocumentComponentType = NextCompon export class Head extends React.Component {} export class Main extends React.Component {} export class NextScript extends React.Component {} -export default class Document extends React.Component< - IP & DocumentProps -> { - getInitialProps(context: C): Promise | IP; +export default class Document

extends React.Component

{ + static getInitialProps(context: NextDocumentContext): DocumentProps; } diff --git a/types/next/index.d.ts b/types/next/index.d.ts index c66e4c82ac..f4b7affedd 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -33,7 +33,7 @@ declare namespace next { * * @template Q Query object schema. */ - interface NextContext { + interface NextContext { /** path section of URL */ pathname: string; /** query string section of URL parsed as an object */ diff --git a/types/next/test/next-app-tests.tsx b/types/next/test/next-app-tests.tsx index 331df9e92f..8cf3e30655 100644 --- a/types/next/test/next-app-tests.tsx +++ b/types/next/test/next-app-tests.tsx @@ -1,11 +1,12 @@ import * as React from "react"; import App, { Container, NextAppContext, AppProps, AppComponentType } from "next/app"; +import { DefaultQuery } from "next/router"; interface NextComponentProps { example: string; } -interface TypedQuery { +interface TypedQuery extends DefaultQuery { id?: string; } @@ -32,11 +33,12 @@ class TestAppWithProps extends App { } } -class TestAppWithTypedQuery extends App<{}, NextAppContext> { +class TestAppWithTypedQuery extends App { static async getInitialProps({ ctx }: NextAppContext) { const { id } = ctx.query; const processQuery = (id?: string) => id; processQuery(id); + return { pageProps: id }; } } diff --git a/types/next/test/next-component-tests.tsx b/types/next/test/next-component-tests.tsx index 4ba145ee15..57e397c5b0 100644 --- a/types/next/test/next-component-tests.tsx +++ b/types/next/test/next-component-tests.tsx @@ -1,11 +1,12 @@ import * as React from "react"; import { NextStatelessComponent, NextContext, NextComponentType } from "next"; +import { DefaultQuery } from "next/router"; interface NextComponentProps { example: string; } -interface TypedQuery { +interface TypedQuery extends DefaultQuery { id?: string; }