Search code examples
angulartypescriptangular-cliangular9angular-cli-v9

Angualar 10 : Add descritpion (*d.ts) file manually to compilation


I have a angular library which has the description files *.d.ts. in a below structure

├ src
│  ├ my-lib
│  │   ├ my-typedef.d.ts
│  │      
│  │
│  └public_apit.ts
│  
└ tsconfig.lib.json

On tsconfig.lib.json i have include it like below:

"include": [
    "src/lib/typedefs"
  ],

Edit

Before upgrading to 10 it was set to angular 8. This files were compiled in the final build package, but after Angular 10. I am facing this issue. though other folders are there but typedefs.

I see on angular upgrade guidelines that we need to add manually but not sure what is the correct way.

We have updated the tsconfig.app.json to limit the files compiled. If you rely on other files being included in the compilation, such as a typings.d.ts file, you need to manually add it to the compilation.

https://update.angular.io/?l=3&v=8.0-9.0

repo to the issue: https://github.com/amirgc/angular10-ng-build.git

  • Download the repo.
  • npm install
  • ng build

Solution

  • I found out that this is the expected behavior as type definitions are not emitted with the upgdrade of ng-packagr. If we want to emit type description. To emit the .d.ts we can use the assets option, or alternatively change the file to a .ts extensions. we can add below section on ng-package.json file.

    {
      "ngPackage": {
        "assets": [
          "CHANGELOG.md",
          "./typedefs/**/*.d.ts"
        ],
        "lib": {
          ...
        }
      }
    }