Add NextStatelessComponent interface

This commit is contained in:
Resi Respati
2018-05-11 22:38:21 +07:00
parent 78a788e70f
commit a47662329c
3 changed files with 34 additions and 1 deletions
+6
View File
@@ -3,6 +3,7 @@
// Definitions by: Drew Hays <https://github.com/dru89>
// Brice BERNARD <https://github.com/brikou>
// James Hegedus <https://github.com/jthegedus>
// Resi Respati <https://github.com/resir014>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6
@@ -39,6 +40,11 @@ declare namespace next {
}
}
type NextSFC<P = {}> = NextStatelessComponent<P>;
interface NextStatelessComponent<P = {}> extends React.StatelessComponent<P> {
getInitialProps?: (ctx: NextContext) => Promise<any>;
}
type UrlLike = url.UrlObject | url.Url;
interface ServerConfig {
+26
View File
@@ -0,0 +1,26 @@
import * as React from "react";
import { NextStatelessComponent } from "next";
interface NextComponentProps {
example: string
}
class ClassNext extends React.Component<NextComponentProps> {
async getInitialProps() {
return { example: 'example' }
}
render() {
return (
<div>I'm a stateless component! {this.props.example}</div>
)
}
}
const StatelessNext: NextStatelessComponent<NextComponentProps> = ({ example }) => (
<div>I'm a stateless component! {example}</div>
)
StatelessNext.getInitialProps = async () => {
return { example: 'example' }
}
+2 -1
View File
@@ -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"
]
}