Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types for getInitialProps #7162

Merged
merged 6 commits into from Apr 28, 2019

Conversation

Projects
2 participants
@lfades
Copy link
Member

commented Apr 25, 2019

This PR adds support for:

import React from 'react'
import { NextPage } from 'next'

const Page: NextPage<{ world: string }> = ({ world }) => <h1>Hello {world}</h1>

Page.getInitialProps = async (ctx) => ({ world: 'world' })

The same in a class:

import React from 'react'
import { NextPageContext } from 'next'

export default class Page extends React.Component<{ world: string }> {
  static async getInitialProps(ctx: NextPageContext) {
    return { world: 'test' }
  }

  render() {
    return <h1>Hello {this.props.world}</h1>
  }
}

We should probably document this somehow.

@lfades lfades requested review from dav-is, ijjk, Timer and timneutkens as code owners Apr 25, 2019

@lfades lfades changed the title Added types for getInitialProps Add types for getInitialProps Apr 25, 2019

@github-actions

This comment has been minimized.

Copy link

commented Apr 25, 2019

Stats from current PR

Click to expand stats
zeit/next.js canary lfades/next.js feat/page-types Change
Build Duration 11.6s 11.5s -98ms
node_modules Size 39.6 MB 39.6 MB ⚠️ +285 B
Total Bundle (main, webpack, commons) Size 207 kB 207 kB
Total Bundle (main, webpack, commons) gzip Size 68.2 kB 68.2 kB
Client _app Size 2.18 kB 2.18 kB
Client _app gzip Size 931 B 931 B
Client _error Size 14.2 kB 14.2 kB
Client _error gzip Size 5.39 kB 5.39 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 3.59 kB 3.59 kB
Client pages/link gzip Size 1.61 kB 1.61 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 27.9 kB 27.9 kB
Client main gzip Size 9.64 kB 9.64 kB
Client commons Size 177 kB 177 kB
Client commons gzip Size 57.4 kB 57.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Base Rendered Size 1.34 kB 1.34 kB
Build Dir Size 628 kB 628 kB
Click to expand serverless stats
zeit/next.js canary lfades/next.js feat/page-types Change
Build Duration 14.4s 14.2s -175ms
node_modules Size 39.6 MB 39.6 MB ⚠️ +285 B
Total Bundle (main, webpack, commons) Size 207 kB 207 kB
Total Bundle (main, webpack, commons) gzip Size 68.2 kB 68.2 kB
Client _app Size 2.18 kB 2.18 kB
Client _app gzip Size 931 B 931 B
Client _error Size 14.2 kB 14.2 kB
Client _error gzip Size 5.39 kB 5.39 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 3.59 kB 3.59 kB
Client pages/link gzip Size 1.61 kB 1.61 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 27.9 kB 27.9 kB
Client main gzip Size 9.64 kB 9.64 kB
Client commons Size 177 kB 177 kB
Client commons gzip Size 57.4 kB 57.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Serverless pages/link Size 327 kB 327 kB
Serverless pages/link gzip Size 87.5 kB 87.5 kB ⚠️ +1 B
Serverless pages/index Size 321 kB 321 kB
Serverless pages/index gzip Size 85.6 kB 85.6 kB ⚠️ +1 B
Serverless pages/_error Size 322 kB 322 kB
Serverless pages/_error gzip Size 85.3 kB 85.3 kB
Serverless pages/routerDirect Size 321 kB 321 kB
Serverless pages/routerDirect gzip Size 85.6 kB 85.6 kB ⚠️ +2 B
Serverless pages/withRouter Size 321 kB 321 kB
Serverless pages/withRouter gzip Size 85.7 kB 85.7 kB ⚠️ +2 B
Build Dir Size 2.19 MB 2.19 MB
@github-actions

This comment has been minimized.

Copy link

commented Apr 25, 2019

Stats from current PR

Click to expand stats
zeit/next.js canary lfades/next.js feat/page-types Change
Build Duration 12.4s 12.8s ⚠️ +450ms
node_modules Size 39.6 MB 39.6 MB ⚠️ +275 B
Total Bundle (main, webpack, commons) Size 207 kB 207 kB
Total Bundle (main, webpack, commons) gzip Size 68.2 kB 68.2 kB
Client _app Size 2.18 kB 2.18 kB
Client _app gzip Size 931 B 931 B
Client _error Size 14.2 kB 14.2 kB
Client _error gzip Size 5.39 kB 5.39 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 3.59 kB 3.59 kB
Client pages/link gzip Size 1.61 kB 1.61 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 27.9 kB 27.9 kB
Client main gzip Size 9.64 kB 9.64 kB
Client commons Size 177 kB 177 kB
Client commons gzip Size 57.4 kB 57.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Base Rendered Size 1.34 kB 1.34 kB
Build Dir Size 628 kB 628 kB
Click to expand serverless stats
zeit/next.js canary lfades/next.js feat/page-types Change
Build Duration 14.9s 14.8s -125ms
node_modules Size 39.6 MB 39.6 MB ⚠️ +275 B
Total Bundle (main, webpack, commons) Size 207 kB 207 kB
Total Bundle (main, webpack, commons) gzip Size 68.2 kB 68.2 kB
Client _app Size 2.18 kB 2.18 kB
Client _app gzip Size 931 B 931 B
Client _error Size 14.2 kB 14.2 kB
Client _error gzip Size 5.39 kB 5.39 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 3.59 kB 3.59 kB
Client pages/link gzip Size 1.61 kB 1.61 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 27.9 kB 27.9 kB
Client main gzip Size 9.64 kB 9.64 kB
Client commons Size 177 kB 177 kB
Client commons gzip Size 57.4 kB 57.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Serverless pages/link Size 327 kB 327 kB
Serverless pages/link gzip Size 87.5 kB 87.5 kB -4 B
Serverless pages/index Size 321 kB 321 kB
Serverless pages/index gzip Size 85.6 kB 85.6 kB -2 B
Serverless pages/_error Size 322 kB 322 kB
Serverless pages/_error gzip Size 85.3 kB 85.3 kB -2 B
Serverless pages/routerDirect Size 321 kB 321 kB
Serverless pages/routerDirect gzip Size 85.6 kB 85.6 kB -2 B
Serverless pages/withRouter Size 321 kB 321 kB
Serverless pages/withRouter gzip Size 85.7 kB 85.7 kB -2 B
Build Dir Size 2.19 MB 2.19 MB

@timneutkens timneutkens added this to In progress in TypeScript via automation Apr 26, 2019

lfades added some commits Apr 26, 2019

@github-actions

This comment has been minimized.

Copy link

commented Apr 26, 2019

Stats from current PR

Click to expand stats
zeit/next.js canary lfades/next.js feat/page-types Change
Build Duration 12.5s 12.1s -429ms
node_modules Size 39.6 MB 39.6 MB -294 B
Total Bundle (main, webpack, commons) Size 207 kB 207 kB
Total Bundle (main, webpack, commons) gzip Size 68.2 kB 68.2 kB
Client _app Size 2.13 kB 2.13 kB
Client _app gzip Size 919 B 919 B
Client _error Size 14.2 kB 14.2 kB
Client _error gzip Size 5.39 kB 5.39 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 3.62 kB 3.62 kB
Client pages/link gzip Size 1.63 kB 1.63 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 27.9 kB 27.9 kB
Client main gzip Size 9.64 kB 9.64 kB
Client commons Size 177 kB 177 kB
Client commons gzip Size 57.4 kB 57.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Base Rendered Size 1.34 kB 1.34 kB
Build Dir Size 637 kB 637 kB
Click to expand serverless stats
zeit/next.js canary lfades/next.js feat/page-types Change
Build Duration 14.5s 15.3s ⚠️ +866ms
node_modules Size 39.6 MB 39.6 MB -294 B
Total Bundle (main, webpack, commons) Size 207 kB 207 kB
Total Bundle (main, webpack, commons) gzip Size 68.2 kB 68.2 kB -1 B
Client _app Size 2.13 kB 2.13 kB
Client _app gzip Size 919 B 919 B
Client _error Size 14.2 kB 14.2 kB
Client _error gzip Size 5.39 kB 5.39 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 3.62 kB 3.62 kB
Client pages/link gzip Size 1.63 kB 1.63 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 27.9 kB 27.9 kB
Client main gzip Size 9.64 kB 9.64 kB -1 B
Client commons Size 177 kB 177 kB
Client commons gzip Size 57.4 kB 57.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Serverless pages/link Size 327 kB 327 kB
Serverless pages/link gzip Size 87.5 kB 87.5 kB -3 B
Serverless pages/index Size 321 kB 321 kB
Serverless pages/index gzip Size 85.6 kB 85.6 kB -5 B
Serverless pages/_error Size 322 kB 322 kB
Serverless pages/_error gzip Size 85.3 kB 85.3 kB -4 B
Serverless pages/routerDirect Size 321 kB 321 kB
Serverless pages/routerDirect gzip Size 85.6 kB 85.6 kB -4 B
Serverless pages/withRouter Size 321 kB 321 kB
Serverless pages/withRouter gzip Size 85.7 kB 85.7 kB -5 B
Build Dir Size 2.19 MB 2.19 MB
@github-actions

This comment has been minimized.

Copy link

commented Apr 27, 2019

Stats from current PR

Click to expand stats
zeit/next.js canary lfades/next.js feat/page-types Change
Build Duration 12.6s 12.1s -410ms
node_modules Size 35.8 MB 39.6 MB ⚠️ +3.81 MB
Total Bundle (main, webpack, commons) Size 207 kB 207 kB -50 B
Total Bundle (main, webpack, commons) gzip Size 68.2 kB 68.2 kB -28 B
Client _app Size 2.13 kB 2.13 kB
Client _app gzip Size 919 B 919 B
Client _error Size 14.2 kB 14.2 kB
Client _error gzip Size 5.39 kB 5.39 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 3.62 kB 3.62 kB
Client pages/link gzip Size 1.63 kB 1.63 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 27.9 kB 27.9 kB ⚠️ +15 B
Client main gzip Size 9.64 kB 9.64 kB -1 B
Client commons Size 177 kB 177 kB -65 B
Client commons gzip Size 57.4 kB 57.4 kB -27 B
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Base Rendered Size 1.34 kB 1.34 kB
Build Dir Size 637 kB 637 kB -92 B
Click to expand serverless stats
zeit/next.js canary lfades/next.js feat/page-types Change
Build Duration 14.4s 14.6s ⚠️ +216ms
node_modules Size 35.8 MB 39.6 MB ⚠️ +3.81 MB
Total Bundle (main, webpack, commons) Size 207 kB 207 kB -50 B
Total Bundle (main, webpack, commons) gzip Size 68.2 kB 68.2 kB -28 B
Client _app Size 2.13 kB 2.13 kB
Client _app gzip Size 919 B 919 B
Client _error Size 14.2 kB 14.2 kB
Client _error gzip Size 5.39 kB 5.39 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 3.62 kB 3.62 kB
Client pages/link gzip Size 1.63 kB 1.63 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 27.9 kB 27.9 kB ⚠️ +15 B
Client main gzip Size 9.64 kB 9.64 kB -1 B
Client commons Size 177 kB 177 kB -65 B
Client commons gzip Size 57.4 kB 57.4 kB -27 B
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Serverless pages/link Size 327 kB 327 kB ⚠️ +5 B
Serverless pages/link gzip Size 87.5 kB 87.5 kB -2 B
Serverless pages/index Size 321 kB 321 kB ⚠️ +5 B
Serverless pages/index gzip Size 85.6 kB 85.6 kB -1 B
Serverless pages/_error Size 322 kB 322 kB ⚠️ +5 B
Serverless pages/_error gzip Size 85.3 kB 85.3 kB -1 B
Serverless pages/routerDirect Size 321 kB 321 kB ⚠️ +5 B
Serverless pages/routerDirect gzip Size 85.6 kB 85.6 kB -1 B
Serverless pages/withRouter Size 321 kB 321 kB ⚠️ +5 B
Serverless pages/withRouter gzip Size 85.7 kB 85.7 kB -2 B
Build Dir Size 2.19 MB 2.19 MB -71 B

@lfades lfades merged commit 2eee876 into zeit:canary Apr 28, 2019

4 of 5 checks passed

ci/circleci: test Your tests failed on CircleCI
Details
ci/circleci: build Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage decreased (-0.1%) to 49.362%
Details
zeit.next.js #20190427.4 succeeded
Details

TypeScript automation moved this from In progress to Done Apr 28, 2019

rajendraarora16 added a commit to rajendraarora16/next.js that referenced this pull request Apr 28, 2019

Merge pull request #130 from zeit/canary
Add types for getInitialProps (zeit#7162)

ijjk added a commit to ijjk/next.js that referenced this pull request Apr 28, 2019

Add types for getInitialProps (zeit#7162)
* Added types for pages

@lfades lfades deleted the lfades:feat/page-types branch Apr 30, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.