Search code examples
typescriptwebpackionic2typescript-typingstype-definition

Typescript Definitions Modification


I have a couple of modifications that I need to make to some typescript definition files. Up until now I have been making these modifications manually - a bit of a pain if I wipe out my node_modules directory and start afresh, or if I install my code on a new machine. But the changes are only small and it worked. However now I want to build my code using a service that calls npm install as part of the build process - of course my modifications are unknown to this process. I've included one of the modifications that I have to make below:

Add the following:
adapter(param1: string, param2: any): Static; 

After the first line in node_modules\@types\pouchdb-core\index.d.ts in the following Interface:
interface Static extends EventEmitter

In order to avoid an error with the following statement in data-service.ts:
PouchDB.adapter('writableStream', replicationStream.adapters.writableStream);

My question is how can I make this type of modification outside of my node_modules directory so that the external build process will know about the required modifications.

I am using Ionic 2 which uses Webpack.


Solution

  • I found that I could fix this particular issue by adding the following to my declarations.d.ts file:

    declare namespace PouchDB {
      interface Static {  adapter: any; }
    }