-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tsx workaround, bootstrap next.d.ts, add tslint deps (#2885)
- Loading branch information
1 parent
7ee66de
commit 45e26f2
Showing
9 changed files
with
50 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
**/*.js | ||
*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,14 @@ | ||
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-typescript) | ||
|
||
# TypeScript Next.js example | ||
|
||
This is a really simple project that show the usage of Next.js with TypeScript. | ||
|
||
## How to use it? | ||
|
||
``` | ||
npm install # to install dependencies | ||
npm run dev # to compile TypeScript files and to run next.js | ||
npm install | ||
npm run dev | ||
``` | ||
|
||
Output JS files are aside the related TypeScript ones. | ||
|
||
## To fix | ||
In tsconfig.json the options `jsx="react"` compiles JSX syntax into nested React.createElement calls. | ||
This solution doesn't work well with some Next.js features like `next/head` or `next/link`. | ||
The workaround is to create JS files that just return the mentioned module and require them from TSX files. | ||
Like | ||
|
||
```js | ||
import Link from 'next/link' | ||
|
||
export default Link | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
declare module 'next/link' { | ||
import { Url } from 'url' | ||
|
||
export default class Link extends React.Component< | ||
{ | ||
href: string | Url; | ||
}, | ||
{} | ||
> {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => <div>About us</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import * as React from 'react' | ||
import MyComponent from '../components/MyComponent' | ||
import Link from 'next/link' | ||
|
||
export default () => | ||
export default () => | ||
<div> | ||
<h1>Hello world</h1> | ||
<MyComponent /> | ||
Hello World.{' '} | ||
<Link href="/about"> | ||
<a>About</a> | ||
</Link> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es2015", | ||
"jsx": "react", | ||
"allowJs": true | ||
} | ||
"compilerOptions": { | ||
"jsx": "react-native", | ||
"module": "commonjs", | ||
"strict": true, | ||
"target": "es2017" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"defaultSeverity": "error", | ||
"extends": ["tslint:recommended"], | ||
"jsRules": {}, | ||
"rules": { | ||
"quotemark": [true, "single", "jsx-double"], | ||
"semicolon": [true, "never"] | ||
}, | ||
"rulesDirectory": [] | ||
} |