I have a project in TypeScript that I am packaging as a library to be used by both JavaScript and TypeScript projects. After compiling, I upload the .js and .d.ts files to npm. The main.ts file exports the following:
interface MyInterface{
// ...
}
class MyClass{
public myMethod(): MyInterface { /* code */ }
}
export = new MyClass();
A JavaScript project can easily install and import the library like this:
const myLib=require('my-lib');
myLib.myMethod(); // Works fine
Similarly, a TypeScript project can also import the library successfully:
import * as myLib from 'my-class';
myLib.myMethod(); // Works as expected
However, I also want to export MyInterface
for TypeScript projects so that they can use it like this when importing my library:
import {MyInterface} from 'my-lib';
function anotherFunction(arg: MyInterface){
}
I am unsure about how to properly export components in my main.ts file in order to achieve this functionality while still supporting JavaScript-based projects.