cachegoose icon indicating copy to clipboard operation
cachegoose copied to clipboard

Added typescript type definitions for typescript and fixes Model.distinct() (close #52)

Open xrip opened this issue 5 years ago • 7 comments
trafficstars

Those little fixes would be very useful for community. I've using chachegoose with typescript for a long time and want to share my definitions for community. Also, here is some fix for .distinct operation which not needs an hydrate it works like .lean

xrip avatar Apr 17 '20 09:04 xrip

Need it :)

riderx avatar Apr 20 '20 09:04 riderx

@Akhil-bridge Did you extends global mongoose object with cache goose? Like

import mongoose from 'mongoose';
import cachegoose from 'cachegoose';
import redis from '../redis';

const mongo = function mongo(config: string): mongoose.Connection {
    const options = {
        useUnifiedTopology: true,
        useNewUrlParser: true,
        useCreateIndex: true,
        useFindAndModify: false,
    };

    mongoose.connect(config, options);

    cachegoose(mongoose, redis);

    return mongoose.connection;
};

export default mongo(process.env.MONGODB as string);

Looks like your IDE resolves not extended type definition by cachegoose

xrip avatar Apr 21 '20 12:04 xrip

Thanks xrip This worked..!! import * as cachegoose from 'cachegoose'; Changed according to the below solution https://stackoverflow.com/questions/56238356/understanding-esmoduleinterop-in-tsconfig-file

Akhil-bridge avatar Apr 21 '20 13:04 Akhil-bridge

Could you please merge this @boblauer ?

Akhil-bridge avatar Jun 11 '20 14:06 Akhil-bridge

@xrip do you know how to keep node_modules updated with the changes in the forked repo? I don't think these changes been merged soon.

Akhil-bridge avatar Jun 11 '20 14:06 Akhil-bridge

You can add package directly from my github repo e.g ''' npm install https://github.com/xrip/cachegoose

xrip avatar Jun 14 '20 05:06 xrip

@xrip I seem to get a bunch of build errors when trying to use your repo.

node_modules/cachegoose/index.d.ts:21:2 - error TS2666: Exports and export assignments are not permitted in module augmentations.

21  export = cachegoose;
    ~~~~~~

node_modules/cachegoose/index.d.ts:29:9 - error TS2371: A parameter initializer is only allowed in a function or constructor implementation. 

29      cache(ttl: number = 60, customKey: string = ''): this
              ~~~~~~~~~~~~~~~~

node_modules/cachegoose/index.d.ts:29:27 - error TS2371: A parameter initializer is only allowed in a function or constructor implementation.

29      cache(ttl: number = 60, customKey: string = ''): this
                                ~~~~~~~~~~~~~~~~~~~~~~

node_modules/cachegoose/index.d.ts:30:9 - error TS2371: A parameter initializer is only allowed in a function or constructor implementation. 

30      cache(customKey: string = ''): this
              ~~~~~~~~~~~~~~~~~~~~~~

node_modules/cachegoose/index.d.ts:31:9 - error TS2371: A parameter initializer is only allowed in a function or constructor implementation.

31      cache(ttl: number = 60): this

devcshort avatar Aug 24 '20 21:08 devcshort