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
d7152f6a
Commit
d7152f6a
authored
May 14, 2019
by
Lukáš Huvar
Committed by
Luis Fernando Alvarez D
May 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update typescript example to reflects out of box usage (#7235)
parent
693ba44a
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
30 additions
and
43 deletions
+30
-43
.babelrc
examples/with-typescript/.babelrc
+0
-6
ListDetail.tsx
examples/with-typescript/components/ListDetail.tsx
+1
-1
next.config.js
examples/with-typescript/next.config.js
+0
-2
package.json
examples/with-typescript/package.json
+4
-5
detail.tsx
examples/with-typescript/pages/detail.tsx
+4
-7
index.tsx
examples/with-typescript/pages/index.tsx
+2
-1
list-class.tsx
examples/with-typescript/pages/list-class.tsx
+2
-2
list-fc.tsx
examples/with-typescript/pages/list-fc.tsx
+3
-4
tsconfig.json
examples/with-typescript/tsconfig.json
+14
-15
No files found.
examples/with-typescript/.babelrc
deleted
100644 → 0
View file @
693ba44a
{
"presets": [
"next/babel",
"@zeit/next-typescript/babel"
]
}
\ No newline at end of file
examples/with-typescript/components/ListDetail.tsx
View file @
d7152f6a
...
...
@@ -6,7 +6,7 @@ type ListDetailProps = {
item
:
IDataObject
;
}
const
ListDetail
:
React
.
F
C
<
ListDetailProps
>
=
({
item
:
user
})
=>
(
const
ListDetail
:
React
.
F
unctionComponent
<
ListDetailProps
>
=
({
item
:
user
})
=>
(
<
div
>
<
h1
>
Detail for
{
user
.
name
}
</
h1
>
<
p
>
ID:
{
user
.
id
}
</
p
>
...
...
examples/with-typescript/next.config.js
deleted
100644 → 0
View file @
693ba44a
const
withTypescript
=
require
(
'@zeit/next-typescript'
)
module
.
exports
=
withTypescript
()
examples/with-typescript/package.json
View file @
d7152f6a
...
...
@@ -9,15 +9,14 @@
},
"dependencies"
:
{
"@zeit/next-typescript"
:
"^1.1.1"
,
"next"
:
"^
7.0.2
"
,
"next"
:
"^
8.1.1-canary.23
"
,
"react"
:
"^16.7.0"
,
"react-dom"
:
"^16.7.0"
},
"devDependencies"
:
{
"@types/next"
:
"^7.0.6"
,
"@types/react"
:
"^16.4.16"
,
"@types/react-dom"
:
"16.0.11"
,
"typescript"
:
"3.2.4"
"@types/node"
:
"^11.13.9"
,
"@types/react"
:
"^16.8.15"
,
"@types/react-dom"
:
"^16.0.11"
},
"license"
:
"ISC"
}
examples/with-typescript/pages/detail.tsx
View file @
d7152f6a
import
*
as
React
from
'react'
import
{
NextContext
}
from
'next'
import
{
Next
Page
Context
}
from
'next'
import
Layout
from
'../components/Layout'
import
IDataObject
from
'../interfaces'
import
{
findData
}
from
'../utils/sample-api'
import
ListDetail
from
'../components/ListDetail'
;
type
RequestQuery
=
{
id
:
string
,
}
type
Props
=
{
item
?:
IDataObject
,
errors
?:
string
,
}
class
ListDetailPage
extends
React
.
Component
<
Props
>
{
static
getInitialProps
=
async
({
query
}:
Next
Context
<
RequestQuery
>
)
=>
{
static
getInitialProps
=
async
({
query
}:
Next
PageContext
)
=>
{
try
{
const
item
=
await
findData
(
query
.
id
);
const
{
id
}
=
query
const
item
=
await
findData
(
Array
.
isArray
(
id
)
?
id
[
0
]:
id
);
return
{
item
}
}
catch
(
err
)
{
return
{
errors
:
err
.
message
}
...
...
examples/with-typescript/pages/index.tsx
View file @
d7152f6a
import
*
as
React
from
'react'
import
Link
from
'next/link'
import
Layout
from
'../components/Layout'
import
{
NextPage
}
from
'next'
;
const
IndexPage
:
React
.
FunctionComponent
=
()
=>
{
const
IndexPage
:
NextPage
=
()
=>
{
return
(
<
Layout
title=
"Home | Next.js + TypeScript Example"
>
<
h1
>
Hello Next.js 👋
</
h1
>
...
...
examples/with-typescript/pages/list-class.tsx
View file @
d7152f6a
import
*
as
React
from
'react'
import
{
NextContext
}
from
'next'
import
{
Next
Page
Context
}
from
'next'
import
Link
from
'next/link'
;
import
Layout
from
'../components/Layout'
...
...
@@ -13,7 +13,7 @@ type Props = {
}
class
ListClass
extends
React
.
Component
<
Props
>
{
static
async
getInitialProps
({
pathname
}:
NextContext
)
{
static
async
getInitialProps
({
pathname
}:
Next
Page
Context
)
{
// Example for including initial props in a Next.js page.
// Don't forget to include the respective types for any
// props passed into the component
...
...
examples/with-typescript/pages/list-fc.tsx
View file @
d7152f6a
import
{
Next
FunctionComponent
,
NextContext
}
from
'next'
import
{
Next
Page
}
from
'next'
import
Link
from
'next/link'
;
import
Layout
from
'../components/Layout'
import
List
from
'../components/List'
import
IDataObject
from
'../interfaces'
...
...
@@ -11,7 +10,7 @@ type Props = {
pathname
:
string
,
}
const
ListFunction
:
Next
FunctionComponent
<
Props
>
=
({
items
,
pathname
})
=>
(
const
ListFunction
:
Next
Page
<
Props
>
=
({
items
,
pathname
})
=>
(
<
Layout
title=
"List Example (as Functional Component) | Next.js + TypeScript Example"
>
<
h1
>
List Example (as Function Component)
</
h1
>
<
p
>
You are currently on:
{
pathname
}
</
p
>
...
...
@@ -20,7 +19,7 @@ const ListFunction: NextFunctionComponent<Props> = ({ items, pathname }) => (
</
Layout
>
)
ListFunction
.
getInitialProps
=
async
({
pathname
}
:
NextContext
)
=>
{
ListFunction
.
getInitialProps
=
async
({
pathname
})
=>
{
// Example for including initial props in a Next.js function compnent page.
// Don't forget to include the respective types for any props passed into
// the component.
...
...
examples/with-typescript/tsconfig.json
View file @
d7152f6a
{
"compilerOptions"
:
{
"target"
:
"esnext"
,
"module"
:
"esnext"
,
"jsx"
:
"preserve"
,
"lib"
:
[
"dom"
,
"es2017"
],
"moduleResolution"
:
"node"
,
"allowJs"
:
true
,
"noEmit"
:
true
,
"strict"
:
true
,
"allowSyntheticDefaultImports"
:
true
,
"skipLibCheck"
:
true
,
"noUnusedLocals"
:
true
,
"noUnusedParameters"
:
true
,
"removeComments"
:
false
,
"preserveConstEnums"
:
true
,
"sourceMap"
:
true
"allowJs"
:
true
,
"alwaysStrict"
:
true
,
"esModuleInterop"
:
true
,
"isolatedModules"
:
true
,
"jsx"
:
"preserve"
,
"lib"
:
[
"dom"
,
"es2017"
],
"module"
:
"esnext"
,
"moduleResolution"
:
"node"
,
"noEmit"
:
true
,
"noFallthroughCasesInSwitch"
:
true
,
"noUnusedLocals"
:
true
,
"noUnusedParameters"
:
true
,
"strict"
:
true
,
"target"
:
"esnext"
}
}
\ No newline at end of file
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