I am in the process of developing a Typescript package to be released on NPM. Along with the main declaration file produced by the Typescript compiler, I also want to include some custom declarations. However, when this package is installed as a dependency in another project, Typescript only recognizes the generated declaration file and not the additional ones that I have included.
For instance, if my package were named "my-package":
//In typings/my-interface.d.ts
declare module "my-package/interfaces" {
export interface MyInterface { ... }
}
Within the original package, I can freely use this declaration by importing it with
import { MyInterface } from "my-package/interfaces"
. The issue arises when Typescript cannot locate "my-package/interfaces"
within another project where this package is used as a dependency. It seems to only recognize "my-package"
, even though the custom declarations are present in the package and referenced within the compiled declaration.
To illustrate with a practical example, imagine if lodash was developed in Typescript and the developer wanted to incorporate declarations for specific functions alongside the main lodash declaration:
declare module "lodash/some" {
export function ...
}
declare module "lodash/forOwn" {
export function ...
}
Is it feasible to include custom declarations in an NPM package and ensure that Typescript can detect them in addition to the compiled declaration?