Andrews Gilbert
Andrews Gilbert

Reputation: 21

crypto-pouch showing import error in angular

I have imported crypto pouch in angular like below

import CryptoPouch from 'crypto-pouch';

But its showing error like below,

Could not find a declaration file for module 'crypto-pouch'. '/home/excercise_task/pouchDB/pouchApp/node_modules/crypto-pouch/index.js' implicitly has an 'any' type. Try npm i --save-dev @types/crypto-pouch if it exists or add a new declaration (.d.ts) file containing declare module 'crypto-pouch';ts(7016)

Upvotes: -1

Views: 181

Answers (2)

RamblinRose
RamblinRose

Reputation: 4963

Update
I ended up writing the type definition for crypto-pouch which merged at DefinitelyTyped, so just do this

$ npm install --save-dev @types/crypto-pouch

and don't use the work-around below 👍


With respect to my comment on the OP, since [crypto-pouch](https://github.com/calvinmetcalf/crypto-pouch) only has two methods, and I've never written a pouchy plugin declaration, here's this. Just copy this content and place in your project, e.g. `src\crypto-pouch.d.ts` for an angular project. Intellisense should pickup this up and the ts(7016) should evaporate.
// extend PouchDB for the crypto-pouch plugin 

declare module "crypto-pouch"; // define the module for this definition

declare namespace PouchDB {
    namespace CryptoPouch {
        type Options = {
            /* A string password, used to encrypt documents. */
            password: string;
            /* (optional) Array of strings of properties that will not be encrypted. */
            ignore?: string[];
        };
    }
    /* Plugin */
    interface Database<Content extends {} = {}> {
        /**
         *
         * @param options See CryptoPouch.Options
         */
        crypto(options: CryptoPouch.Options): Promise<void>;
        /**
         *
         * @param password A string password, used to encrypt documents.
         * @param ignore Array of strings of properties that will not be encrypted.
         */
        crypto(password: string, ignore?: string[]): Promise<void>;
        /**
         * Disables encryption on the database and forgets your password.
         */
        removeCrypto(): void;
    }
}

Upvotes: 0

dom.macs
dom.macs

Reputation: 796

Change import statement to require:

const CryptoPouch = require('crypto-pouch');

If you get could not find name require like the message below:

Cannot find name 'require'. Do you need to install type definitions for node?

Run:

npm i --save-dev @types/node

Upvotes: 0

Related Questions