Commit 6d41ed7e authored by Resi Respati's avatar Resi Respati Committed by Tim Neutkens

[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.
parent ca521b36
// You can include shared interfaces in a separate file and then
// use them in any component by importing them. For example, to
// import the interface below do:
//
// import IDataObject from 'path/to/interfaces';
export default interface IDataObject { export default interface IDataObject {
id: number, id: number
name: string name: string
} }
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
}, },
"dependencies": { "dependencies": {
"@zeit/next-typescript": "^1.1.1", "@zeit/next-typescript": "^1.1.1",
"lint": "^1.1.2",
"next": "^7.0.2", "next": "^7.0.2",
"react": "^16.7.0", "react": "^16.7.0",
"react-dom": "^16.7.0" "react-dom": "^16.7.0"
...@@ -17,9 +16,8 @@ ...@@ -17,9 +16,8 @@
"devDependencies": { "devDependencies": {
"@types/next": "^7.0.6", "@types/next": "^7.0.6",
"@types/react": "^16.4.16", "@types/react": "^16.4.16",
"@types/react-dom": "16.0.8", "@types/react-dom": "16.0.11",
"eslint": "^5.12.0", "typescript": "3.2.4"
"typescript": "3.2.1"
}, },
"license": "ISC" "license": "ISC"
} }
import * as React from "react" import * as React from 'react'
import Link from 'next/link' import Link from 'next/link'
import Layout from '../components/Layout'; import Layout from '../components/Layout'
const about : React.FunctionComponent = () => ( const AboutPage: React.FunctionComponent = () => (
<Layout title="About | Next.js + TypeScript Example"> <Layout title="About | Next.js + TypeScript Example">
<p>This is the about page</p> <p>This is the about page</p>
<p><Link href='/'><a>Go home</a></Link></p> <p><Link href='/'><a>Go home</a></Link></p>
</Layout> </Layout>
) )
export default about; export default AboutPage;
\ No newline at end of file
import * as React from "react" import * as React from 'react'
import Link from 'next/link' import Link from 'next/link'
import Layout from '../components/Layout' import Layout from '../components/Layout'
const index: React.FunctionComponent = () => { const IndexPage: React.FunctionComponent = () => {
return ( return (
<Layout title="Home | Next.js + TypeScript Example"> <Layout title="Home | Next.js + TypeScript Example">
<h1>Hello Next.js 👋</h1> <h1>Hello Next.js 👋</h1>
...@@ -11,4 +11,4 @@ const index: React.FunctionComponent = () => { ...@@ -11,4 +11,4 @@ const index: React.FunctionComponent = () => {
) )
} }
export default index; export default IndexPage;
...@@ -11,15 +11,22 @@ type Props = { ...@@ -11,15 +11,22 @@ type Props = {
class ListClass extends React.Component<Props> { class ListClass extends React.Component<Props> {
static async getInitialProps({ pathname }: NextContext) { static async getInitialProps({ pathname }: NextContext) {
const dataArray: IDataObject[] = // Example for including initial props in a Next.js page.
[{ id: 101, name: 'larry' }, { id: 102, name: 'sam' }, { id: 103, name: 'jill' }, { id: 104, name: pathname }] // Don't forget to include the respective types for any
// props passed into the component
const dataArray: IDataObject[] = [
{ id: 101, name: 'larry' },
{ id: 102, name: 'sam' },
{ id: 103, name: 'jill' },
{ id: 104, name: pathname },
]
return { items: dataArray } return { items: dataArray }
} }
render() { render() {
return ( return (
<Layout title="About | Next.js + TypeScript Example"> <Layout title="List Example | Next.js + TypeScript Example">
<List items={this.props.items} /> <List items={this.props.items} />
</Layout> </Layout>
) )
......
...@@ -7,17 +7,24 @@ type Props = { ...@@ -7,17 +7,24 @@ type Props = {
items: IDataObject[], items: IDataObject[],
} }
const list: NextFunctionComponent<Props> = ({ items }) => ( const ListFunction: NextFunctionComponent<Props> = ({ items }) => (
<Layout title="About | Next.js + TypeScript Example"> <Layout title="List Example (with Function Components) | Next.js + TypeScript Example">
<List items={items} /> <List items={items} />
</Layout> </Layout>
) )
list.getInitialProps = async ({ pathname }: NextContext) => { ListFunction.getInitialProps = async ({ pathname }: NextContext) => {
const dataArray: IDataObject[] = // Example for including initial props in a Next.js function compnent page.
[{ id: 101, name: 'larry' }, { id: 102, name: 'sam' }, { id: 103, name: 'jill' }, { id: 104, name: pathname }] // Don't forget to include the respective types for any props passed into
// the component.
const dataArray: IDataObject[] = [
{ id: 101, name: 'larry' },
{ id: 102, name: 'sam' },
{ id: 103, name: 'jill' },
{ id: 104, name: pathname },
]
return { items: dataArray } return { items: dataArray }
} }
export default list export default ListFunction
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment