Here is a question that has been previously asked: How can a library with type definitions be generated? The answers provided suggest simply setting "declaration" to true in the tsconfig.json file.
For an example of this concept, I have created both example_library and example_library_consumer projects within this GitHub repository:
https://github.com/jmc420/typescript_examples
In the example_library project, I have created an index.ts file that exports specific classes and interfaces:
export * from './ILogin';
export * from './Login';
However, upon compiling, the TypeScript compiler generates an index.d.ts file without including a module declaration.
The library is imported into the example_library_consumer using the following dependency in the package.json file:
"examplelibrary": "file:../example_library"
In the source code (src/ts/index.ts), the library is used as follows:
import {ILogin, Login} from 'examplelibrary';
let login:ILogin = new Login("email@example.com", "password");
console.log("Email "+login.getPassword());
Despite successful compilation, a runtime error occurs when running the code:
var login = new examplelibrary_1.Login("email@example.com", "password");
^
TypeError: examplelibrary_1.Login is not a constructor
This issue may stem from the absence of a "declare module" statement typically present in index.d.ts files for libraries. Can the tsc compiler generate this "declare module" line with the declaration flag set to true?