Генерация .d.ts файлов typescrit для библиотеки на javasсript. Использование отдельной диретокрии для типов

Общая идея описана тут: https://www.typescriptlang.org/docs/hand...

Пример tsconfig.json:

{
  // Change this to match your project
  "include": [
    "src/**/*"
  ],
  "compilerOptions": {
    // Tells TypeScript to read JS files, as
    // normally they are ignored as source files
    "allowJs": true,
    // Generate d.ts files
    "declaration": true,
    // This compiler run should
    // only output d.ts files
    "emitDeclarationOnly": true,
    // Types should go into this directory.
    // Removing this would place the .d.ts files
    // next to the .js files
    "outDir": "types",
    "lib": [
      "es2015"
    ]
  }
}

-- здесь:

  • мы складываем заголовочные файлы в отдельную папку types/ (по умолчанию они ложаться рядом с имеющимися .js файлами)
  • Чтобы при использовании библиотеки работа инструкция типа:
    import jswl from 'js-wrapper-lib'; 

    -- в package.json библиотеки при использовании отдельной папки, приходится указывать путь
    в "types", напр. :

    {
        "name": "js-wrapper-lib",
        "version": "2.0.8",
        "description": "common purpose javascript functions library",
        "main": "./src/jswl.js",
        "types": "./types/jswl.d.ts",
    

Актуальное решение проблемы работы с типами для библиотети js-wrapper-lib можно на гитхабе: https://github.com/it-for-free/js-wrappe...