0

I am working with a third-party library that has a namespace thisLibrary and within that namespace has an interface Options. I would like to add a property to the Options interface and then use the update version of Options within my code. The index.d.ts file for the library looks like this:

export = thisLibrary;
export as namespace thisLibrary;

declare function thisLibrary(elements: HTMLElement | HTMLElement[], options: thisLibrary.Options): void;

declare namespace thisLibrary {
   const propA: boolean;
   let propB: number;

   interface Options{
      list?: ListEntry[] | any[];
      propC?: string;
      propD?: string | number;
   }
}

I would like to be able to import thisLibrary into my code and then add typing for propE?: boolean such that I can pass propE into my function call for thisLibrary and not raise errors.

I'm working within an Angular framework, and my code looks like this:

import * as thisLibrary from 'thisLibrary';

export class MyComponent implements OnInit {
   constructor() {}

   ngOnInit(): void {
      this.doThis()
   }

   private doThis(): void { 
      const myHTML = this.getHTML()
      thisLibrary(myHTML, {
         list: [[a, 10], [b, 7]],
         propC: 'blah blah',
         propD: 10,
         propE: true
      }
   }

At the moment, this code throws an error in my TS linter because propE "does not exist in type Options".

3
  • Start with declare module 'thisLibrary' { namespace thisLibrary { interface Options … } }? Commented Jun 28, 2021 at 15:57
  • Prior to the import? If so, I just tried this, and the type for propE is still undeclared. Commented Jun 28, 2021 at 17:07
  • Shouldn't matter where you declare it, but I think that's the syntax for declaration merging. Commented Jun 28, 2021 at 17:31

0

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.