Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

xrip
Copy link

@xrip xrip commented Apr 17, 2020

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 xrip changed the title Added typescript type definitions for typescript and Model.distinct('field') fix Added typescript type definitions for typescript and fixes Model.distinct() (close #52) Apr 17, 2020
@riderx
Copy link

riderx commented Apr 20, 2020

Need it :)

Copy link

@Akhil-bridge Akhil-bridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xrip It showing me this error after taken your pull request
TS2551: Property 'cache' does not exist on type 'DocumentQuery<IUser, IUser, {}>'. Did you mean 'catch'
image

And see this error
image

@xrip
Copy link
Author

xrip commented Apr 21, 2020

@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

@Akhil-bridge
Copy link

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
Copy link

Could you please merge this @boblauer ?

@Akhil-bridge
Copy link

@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.

@xrip
Copy link
Author

xrip commented Jun 14, 2020

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

@devcshort
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants