TypeScriptの導入
# プラグインを追加
yarn add -D typescript
# tsconfigファイルを作成
code:tsconfig.json
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"jsx": "react",
"strict": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noEmit": true,
"skipLibCheck": true,
"moduleResolution": "node"
}
}
# ファイル名を変更
index.js -> index.tsx
404.js -> 404.tsx
# typecheckを追加
code:package.json
"typecheck": "tsc --noEmit"
# index.tsxを修正
typecheckでエラーが出るので色々消します。
code:index.tsx
import * as React from "react"
// markup
const IndexPage = () => {
return (
<main>
<p>hello gatsby</p>
</main>
)
}
export default IndexPage
typecheckを実行しても大丈夫になりました。