読み方のヒント

矢印ボタン(または ← → キー)でページを移動できます。

第1節 tsconfig.json の役割

1.1 tsconfig.json の形

npx tsc --init で作られる tsconfig.json は、TypeScript 7.0 では次のような内容です(コメントの行を省いています。5.9 以降は同じ内容です)。

{
  "compilerOptions": {
    "module": "nodenext",
    "target": "esnext",
    "types": [],
    "sourceMap": true,
    "declaration": true,
    "declarationMap": true,
    "noUncheckedIndexedAccess": true,
    "exactOptionalPropertyTypes": true,
    "strict": true,
    "jsx": "react-jsx",
    "verbatimModuleSyntax": true,
    "isolatedModules": true,
    "noUncheckedSideEffectImports": true,
    "moduleDetection": "force",
    "skipLibCheck": true
  }
}

compilerOptions の中に、型チェックと変換の設定を書きます。項目は多くありますが、目的で分けると次の4つになります。

目的主な項目
どれくらい厳しく調べるかstrict、noUncheckedIndexedAccess、exactOptionalPropertyTypes
どの JavaScript にするかtarget、module
どのファイルを調べるかinclude、rootDir
何を作るかoutDir、sourceMap、declaration、noEmit

2 / 20