From a47662329cfbdd2978f58a4591248069341c48df Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Fri, 11 May 2018 22:38:21 +0700 Subject: [PATCH] Add NextStatelessComponent interface --- types/next/index.d.ts | 6 ++++++ types/next/test/next-component-tests.tsx | 26 ++++++++++++++++++++++++ types/next/tsconfig.json | 3 ++- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 types/next/test/next-component-tests.tsx diff --git a/types/next/index.d.ts b/types/next/index.d.ts index 3abb22a2a4..52c34542ba 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: Drew Hays // Brice BERNARD // James Hegedus +// Resi Respati // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.6 @@ -39,6 +40,11 @@ declare namespace next { } } + type NextSFC

= NextStatelessComponent

; + interface NextStatelessComponent

extends React.StatelessComponent

{ + getInitialProps?: (ctx: NextContext) => Promise; + } + type UrlLike = url.UrlObject | url.Url; interface ServerConfig { diff --git a/types/next/test/next-component-tests.tsx b/types/next/test/next-component-tests.tsx new file mode 100644 index 0000000000..33ecb6bc93 --- /dev/null +++ b/types/next/test/next-component-tests.tsx @@ -0,0 +1,26 @@ +import * as React from "react"; +import { NextStatelessComponent } from "next"; + +interface NextComponentProps { + example: string +} + +class ClassNext extends React.Component { + async getInitialProps() { + return { example: 'example' } + } + + render() { + return ( +

I'm a stateless component! {this.props.example}
+ ) + } +} + +const StatelessNext: NextStatelessComponent = ({ example }) => ( +
I'm a stateless component! {example}
+) + +StatelessNext.getInitialProps = async () => { + return { example: 'example' } +} diff --git a/types/next/tsconfig.json b/types/next/tsconfig.json index 48d3f0c8be..d22768e4a1 100644 --- a/types/next/tsconfig.json +++ b/types/next/tsconfig.json @@ -33,6 +33,7 @@ "test/next-document-tests.tsx", "test/next-link-tests.tsx", "test/next-dynamic-tests.tsx", - "test/next-router-tests.tsx" + "test/next-router-tests.tsx", + "test/next-component-tests.tsx" ] }