Search code examples
typescriptbootstrap-datetimepicker

Adding members to interfaces declared in a module


I'm trying to use the Bootstrap Datetimepicker plugin in my TypeScript code. I've downloaded the .d.ts definitions for the plugin, but taht one does not include currently the method Datetimepicker.destroy. However, it's present in the plugin, so I would like to use it with type safety.

Normally I would do a simple interface (extension) on my root level like this:

inteface Datetimepicker {
  destroy():void;
}

But in this case it does not work, because the Datetimepicker interface is defined within a BootstrapV3DatetimePicker module in the d.ts file, so this kind of extension doesn't work. I tried this way also:

module BootstrapV3DatetimePicker { 
  inteface Datetimepicker {
    destroy():void;
  }
}

But it doesn't seem to work either, the destroy method is still nto recognized by Visual Studio.

How to add new members to an existing interface if it's defined within a module in an external d.ts file?


Solution

  • Try :

      declare module BootstrapV3DatetimePicker { 
         export inteface Datetimepicker {
           destroy():void;
        }
     }
    

    Notice the export and declare