
.d.tsファイルをちゃんと使うために必要な知識
DRANK
.d.tsファイルとは、TypeScriptにおいて型定義ファイルと呼ばれるファイルのことです。残念なことに、.d.tsファイルは誤った使い方をされているのを見かけることがあります。そこで、この記事では、.d.tsファイルを正しく使うために必要な知識を解説します。.d.tsファイルとは.d.tsファイルについては、とりあえずTypeScript公式による以下の説明を読んでください(Announcing TypeScript 5.5から引用)。Declaration files (a.k.a. .d.ts files) describe the shape of existing libraries and modules to TypeScript. This lightweight description includes the library’s type signatures and excludes implementation details such as the function bodies. They are published so that TypeScript can efficiently check your usage of a library without needing to analyse the library itself. Whilst it is possible to handwrite declaration files, if you are authoring typed code, it’s much safer and simpler to let TypeScript generate them automatically from source files using --declaration.日本語訳: Declaration files(.d.tsファイル)は、Typ…