1

long story short, I have a npm module which exports a function and other function attached to exported function:

// @mycompany/module
...
const someTool = (options) => {
  // do some cool stuff
};

someTool.canUseFeature1 = () => {
  return canUseSomeFeature1();
};

module.exports = someTool;

In my client application, I need to declare type for exported function someTool and for attached function someTool.canUseFeature1.

I'm declaring the type in a file Global.d.ts:

declare module '@mycompany/module' {
  export default function (options: any): any;
}

The question, how to declare someTool.canUseFeature1 in similar manner? The closest answer I found is here, but I could not adapt it to external module.

Valentine
  • 506
  • 6
  • 23

1 Answers1

0

Just found the solution:

Function in js literally is an object, so it worth to use type declaration for objects. And this approach works.

Resulting solution for my case:

declare module '@mycompany/module' {
  function someTool(options: any): any;
  namespace someTool {
    function canUseFeature1() : boolean;
  }
  export = someTool
}
Valentine
  • 506
  • 6
  • 23