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.

1 Answer 1

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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.