Skip to content

English

@yuu1111/tsconfig ​

共有のTypeScript設定

Install ​

bash
bun add -D @yuu1111/tsconfig

Usage ​

tsconfig.json でpresetを1つextendsし、presetが持たないpathをProjectで足す

json
{
  "extends": "@yuu1111/tsconfig/base.json",
  "include": ["src/**/*.ts"]
}

Presets ​

PresetExtends用途
base—他のpresetが継承する厳格なbase
bunbaseBunのglobal型を足す
librarybasedeclarationとsource mapを出してJavaScriptをemitする
declaration-onlylibrarydeclaration fileだけを出す
reactbaseDOM型とJSX transformを足す

base ​

他のpresetはすべて base をextendsする emitせずに型検査だけを行い、emitはpresetまたはbundlerへ任せる

Option値
targetESNext
lib["ESNext"]
modulePreserve
moduleResolutionbundler
moduleDetectionforce
stricttrue
noEmittrue
isolatedModulestrue
verbatimModuleSyntaxtrue
esModuleInteroptrue
resolveJsonModuletrue
skipLibChecktrue
forceConsistentCasingInFileNamestrue
noUncheckedIndexedAccesstrue
noFallthroughCasesInSwitchtrue
exactOptionalPropertyTypestrue
json
{
  "extends": "@yuu1111/tsconfig/base.json"
}

bun ​

types: ["bun"] を足す 利用Projectで @types/bun をinstallする

json
{
  "extends": "@yuu1111/tsconfig/bun.json"
}

library ​

emitを有効にし、declaration、declaration map、source mapを出す

Option値
noEmitfalse
declarationtrue
declarationMaptrue
sourceMaptrue
json
{
  "extends": "@yuu1111/tsconfig/library.json",
  "compilerOptions": {
    "rootDir": "src",
    "outDir": "dist"
  },
  "include": ["src/**/*.ts"]
}

declaration-only ​

library をextendsし、bundlerがJavaScriptを出すbuild向けに emitDeclarationOnly を設定する

json
{
  "extends": "@yuu1111/tsconfig/declaration-only.json",
  "compilerOptions": {
    "rootDir": "src",
    "outDir": "dist"
  },
  "include": ["src/**/*.ts"]
}

react ​

lib へ DOM と DOM.Iterable を足し、jsx: "react-jsx" を設定する

json
{
  "extends": "@yuu1111/tsconfig/react.json",
  "compilerOptions": {
    "outDir": "dist"
  }
}