cachegoose
cachegoose copied to clipboard
Added typescript type definitions for typescript and fixes Model.distinct() (close #52)
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
Need it :)
@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
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
Could you please merge this @boblauer ?
@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.
You can add package directly from my github repo e.g ''' npm install https://github.com/xrip/cachegoose
@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