Skip to content

Commit 6d41ed7

Browse files
resir014timneutkens
authored andcommitted
[with-typescript] Updated typescript and removed unused deps (#6116)
I've updated the TypeScript dependency to the latest version. Also removed some dependencies that may not be needed. I've also fixed tslint errors which may have appeared because of previous updates to this starter kit, as well as added comments to explain some parts of the code.
1 parent ca521b3 commit 6d41ed7

File tree

6 files changed

+39
-21
lines changed

6 files changed

+39
-21
lines changed
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
// You can include shared interfaces in a separate file and then
2+
// use them in any component by importing them. For example, to
3+
// import the interface below do:
4+
//
5+
// import IDataObject from 'path/to/interfaces';
6+
17
export default interface IDataObject {
2-
id: number,
8+
id: number
39
name: string
410
}

examples/with-typescript/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@
99
},
1010
"dependencies": {
1111
"@zeit/next-typescript": "^1.1.1",
12-
"lint": "^1.1.2",
1312
"next": "^7.0.2",
1413
"react": "^16.7.0",
1514
"react-dom": "^16.7.0"
1615
},
1716
"devDependencies": {
1817
"@types/next": "^7.0.6",
1918
"@types/react": "^16.4.16",
20-
"@types/react-dom": "16.0.8",
21-
"eslint": "^5.12.0",
22-
"typescript": "3.2.1"
19+
"@types/react-dom": "16.0.11",
20+
"typescript": "3.2.4"
2321
},
2422
"license": "ISC"
2523
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import * as React from "react"
1+
import * as React from 'react'
22
import Link from 'next/link'
3-
import Layout from '../components/Layout';
3+
import Layout from '../components/Layout'
44

5-
const about : React.FunctionComponent = () => (
5+
const AboutPage: React.FunctionComponent = () => (
66
<Layout title="About | Next.js + TypeScript Example">
77
<p>This is the about page</p>
88
<p><Link href='/'><a>Go home</a></Link></p>
99
</Layout>
1010
)
1111

12-
export default about;
12+
export default AboutPage;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as React from "react"
1+
import * as React from 'react'
22
import Link from 'next/link'
33
import Layout from '../components/Layout'
44

5-
const index: React.FunctionComponent = () => {
5+
const IndexPage: React.FunctionComponent = () => {
66
return (
77
<Layout title="Home | Next.js + TypeScript Example">
88
<h1>Hello Next.js 👋</h1>
@@ -11,4 +11,4 @@ const index: React.FunctionComponent = () => {
1111
)
1212
}
1313

14-
export default index;
14+
export default IndexPage;

examples/with-typescript/pages/list-class.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,22 @@ type Props = {
1111

1212
class ListClass extends React.Component<Props> {
1313
static async getInitialProps({ pathname }: NextContext) {
14-
const dataArray: IDataObject[] =
15-
[{ id: 101, name: 'larry' }, { id: 102, name: 'sam' }, { id: 103, name: 'jill' }, { id: 104, name: pathname }]
14+
// Example for including initial props in a Next.js page.
15+
// Don't forget to include the respective types for any
16+
// props passed into the component
17+
const dataArray: IDataObject[] = [
18+
{ id: 101, name: 'larry' },
19+
{ id: 102, name: 'sam' },
20+
{ id: 103, name: 'jill' },
21+
{ id: 104, name: pathname },
22+
]
1623

1724
return { items: dataArray }
1825
}
1926

2027
render() {
2128
return (
22-
<Layout title="About | Next.js + TypeScript Example">
29+
<Layout title="List Example | Next.js + TypeScript Example">
2330
<List items={this.props.items} />
2431
</Layout>
2532
)

examples/with-typescript/pages/list-fc.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,24 @@ type Props = {
77
items: IDataObject[],
88
}
99

10-
const list: NextFunctionComponent<Props> = ({ items }) => (
11-
<Layout title="About | Next.js + TypeScript Example">
10+
const ListFunction: NextFunctionComponent<Props> = ({ items }) => (
11+
<Layout title="List Example (with Function Components) | Next.js + TypeScript Example">
1212
<List items={items} />
1313
</Layout>
1414
)
1515

16-
list.getInitialProps = async ({ pathname }: NextContext) => {
17-
const dataArray: IDataObject[] =
18-
[{ id: 101, name: 'larry' }, { id: 102, name: 'sam' }, { id: 103, name: 'jill' }, { id: 104, name: pathname }]
16+
ListFunction.getInitialProps = async ({ pathname }: NextContext) => {
17+
// Example for including initial props in a Next.js function compnent page.
18+
// Don't forget to include the respective types for any props passed into
19+
// the component.
20+
const dataArray: IDataObject[] = [
21+
{ id: 101, name: 'larry' },
22+
{ id: 102, name: 'sam' },
23+
{ id: 103, name: 'jill' },
24+
{ id: 104, name: pathname },
25+
]
1926

2027
return { items: dataArray }
2128
}
2229

23-
export default list
30+
export default ListFunction

0 commit comments

Comments
 (0)