LoginSignup
10
6

More than 5 years have passed since last update.

TypeScriptで型定義だけ出力する

Posted at

ライブラリを @babel/preset-typescript · Babel を使ってbabelでコンパイルする場合にコンパイルしただけだと型定義は生成できません。

その場合、tscコマンドに--emitDeclarationOnlyフラグを付けて型定義を生成する必要があります。

"scripts": {
 "build:types": "tsc --emitDeclarationOnly"
}
npm run build:types

また公開する際は、package.jsonに typesフィールドの指定を忘れないようにしましょう。

{
 "main": "./lib/main.js",
 "types": "./lib/main.d.ts"
}
10
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
6