tsconfig.jsonでdeclarationはtrueにする必要があります。またoutDirで出力先も指定します。
{
"compilerOptions": {
"declaration": true,
"outDir": "./dist/types"
}
}あとは、--emitDeclarationOnlyフラグをtscコマンドにつけて実行するだけです。
tsc --emitDeclarationOnly
# 設定ファイル指定
# tsc -P tsconfig.types.json --emitDeclarationOnly設定晒し
僕はtsconfig.types.jsonでこんな設定でやってます。
{
"extends": "@nju33/tsconfig-types",
"include": ["src/**/*"],
"exclude": ["src/__tests__/**/*", "src/**/*test*"],
"compilerOptions": {
"outDir": "dist/types"
}
}おおまかなところは自分の設定ファイルとして別パッケージにまとめてしまって、プロジェクト毎にそれをインストールしてincludeなどパス関連のものだけ再設定している感じです。