I have created an NPM package that includes a class with multiple interfaces defined in a "types.ts" file. However, I am encountering an issue where I am unable to access these interfaces when attempting to use the package myself. It seems that I may need to export the imported interfaces, but the method I found
export import { IMyInterface } from './common/types'
appears to be outdated or deprecated.
Here is my index.ts:
import { IMyInterface, IMyInterface2 } from './common/types';
export class ExampleClass {
public async getInfo(): Promise<IMyInterface[]> {
return await request();
}
}
Although I can see the returned type in VSCode when using this library, I am unable to define variables using these types. For example, using IMyInterface
as a type in the following code snippet results in an error as it cannot be found:
import { ExampleClass } from 'my-library'
const instance = new ExampleClass();
const info: IMyInterface = instance.getInfo();
My question is:
How can I ensure that my library's interfaces are accessible to others who import the Class?