Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
2eee8766
Unverified
Commit
2eee8766
authored
Apr 28, 2019
by
Luis Fernando Alvarez D
Committed by
GitHub
Apr 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add types for getInitialProps (#7162)
* Added types for pages
parent
f66546f9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
3 deletions
+13
-3
utils.ts
packages/next-server/lib/utils.ts
+3
-3
index.d.ts
packages/next/types/index.d.ts
+10
-0
No files found.
packages/next-server/lib/utils.ts
View file @
2eee8766
...
...
@@ -8,8 +8,8 @@ import { BaseRouter } from './router/router'
/**
* Types used by both next and next-server
*/
export
type
NextComponentType
<
C
extends
BaseContext
=
any
,
P
=
any
,
CP
=
{}
>
=
ComponentType
<
C
P
>
&
{
getInitialProps
?(
context
:
C
):
Promise
<
P
>
,
export
type
NextComponentType
<
C
extends
BaseContext
=
IContext
,
IP
=
{},
P
=
{}
>
=
ComponentType
<
P
>
&
{
getInitialProps
?(
context
:
C
):
Promise
<
I
P
>
,
}
export
type
DocumentType
=
NextComponentType
<
DocumentContext
,
DocumentInitialProps
,
DocumentProps
>
...
...
@@ -123,7 +123,7 @@ export function isResSent(res: ServerResponse) {
return
res
.
finished
||
res
.
headersSent
}
export
async
function
loadGetInitialProps
<
C
extends
BaseContext
,
P
=
any
,
CP
=
{}
>
(
Component
:
NextComponentType
<
C
,
P
,
CP
>
,
ctx
:
C
):
Promise
<
P
|
null
>
{
export
async
function
loadGetInitialProps
<
C
extends
BaseContext
,
IP
=
{},
P
=
{}
>
(
Component
:
NextComponentType
<
C
,
IP
,
P
>
,
ctx
:
C
):
Promise
<
I
P
|
null
>
{
if
(
process
.
env
.
NODE_ENV
!==
'production'
)
{
if
(
Component
.
prototype
&&
Component
.
prototype
.
getInitialProps
)
{
const
message
=
`"
${
getDisplayName
(
Component
)}
.getInitialProps()" is defined as an instance method - visit https://err.sh/zeit/next.js/get-initial-props-as-an-instance-method for more information.`
...
...
packages/next/types/index.d.ts
View file @
2eee8766
import
React
from
'react'
import
{
IContext
}
from
'next-server/dist/lib/utils'
;
// Extend the React types with missing properties
declare
module
'react'
{
...
...
@@ -18,3 +19,12 @@ declare module 'react' {
global
?:
boolean
;
}
}
export
type
NextPageContext
=
IContext
export
type
NextPage
<
P
=
{}
>
=
{
(
props
:
P
):
JSX
.
Element
;
getInitialProps
?(
ctx
:
NextPageContext
):
Promise
<
P
>
;
}
export
{
IContext
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment