≪ Today I learned.
RSS購読
    公開日
    タグ
    TypeScript
    著者
    ダーシノ

    .d.tsは参照のみでdistには含まれない

    以下のような*.d.tsファイルはプロジェクト内限定の参照専用型定義ファイルのため、distディレクトリには出力されない。

    // types/global.d.ts
    declare type MyType = { ... }
    
    // types/env.d.ts
    declare module '*.css' {
      const styles: Record<string, string>
      export default styles
    }

    *.d.tsファイルで定義した型定義をライブラリとして提供したい場合は、*.tsに変更し、型をimportして使うことでdistに含まれる。

    // types/global.ts
    export type MyType = { ... }
    
    // index.ts
    import type { MyType } from '../types/global.ts'
    
    type ExtendedMyType = MyType & { ... }

    参考