Angular libraries are written in typescript or compiled in javascript

I am developing a library that will be installed as an Angular module through npm. The library is written in typescript. Prior to Angular 5.0.0, everything worked like a charm, however, starting with 5.0, users began to receive the following errors:

A mistake in. / node_modules / mypackage / index.ts Module build error: Error: /node_modules/mypackage/index.ts is not part of the compilation output. Check other error messages for details.

As a workaround, I can add the include path to the file in tsconfig.json. My question is should I continue to provide the library in typescript or should I compile it in JS and send it as a compiled package and why?

+5
source share
1 answer

Recommendations on publishing typescript code in npm are written at: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html

TL: DR - send js along with the correct type definition.

This will allow any js user to use lib, and ts users can benefit from types. There are very rare cases when you would like to send the ts code as is to allow fine-grained compilation from user level code to node modules.

+4
source

Source: https://habr.com/ru/post/1274494/


All Articles