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

Typescript extending interface #34

Open
xonuzofa opened this issue Jun 12, 2017 · 0 comments
Open

Typescript extending interface #34

xonuzofa opened this issue Jun 12, 2017 · 0 comments

Comments

@xonuzofa
Copy link

I am getting this error in typescript. The code is working but I am getting this error:

both/methods/collections.methods.ts (82, 69): Property 'get' does not exist on type 'CollectionStatic'.

This is because of the interface CollectionStatic does not have the get function. I have attempted to add this but I cannot get it to work.

export module Mongo {
    var Collection: CollectionStatic;
    interface CollectionStatic {
        new <T>(name: string, options?: {
            connection?: Object;
            idGeneration?: string;
            transform?: Function;
        }): Collection<T>;
        //get(name: string, options?): any; //does not work
    }
    interface Collection<T> {
        allow(options: {
            insert?: (userId: string, doc: T) => boolean;
            update?: (userId: string, doc: T, fieldNames: string[], modifier: any) => boolean;
            remove?: (userId: string, doc: T) => boolean;
            fetch?: string[];
            transform?: Function;
        }): boolean;
        deny(options: {
            insert?: (userId: string, doc: T) => boolean;
            update?: (userId: string, doc: T, fieldNames: string[], modifier: any) => boolean;
            remove?: (userId: string, doc: T) => boolean;
            fetch?: string[];
            transform?: Function;
        }): boolean;
        find(selector?: Mongo.Selector | Mongo.ObjectID | string, options?: {
            sort?: Mongo.SortSpecifier;
            skip?: number;
            limit?: number;
            fields?: Mongo.FieldSpecifier;
            reactive?: boolean;
            transform?: Function;
        }): Mongo.Cursor<T>;
        findOne(selector?: Mongo.Selector | Mongo.ObjectID | string, options?: {
            sort?: Mongo.SortSpecifier;
            skip?: number;
            fields?: Mongo.FieldSpecifier;
            reactive?: boolean;
            transform?: Function;
        }): T;
        insert(doc: T, callback?: Function): string;
        rawCollection(): any;
        rawDatabase(): any;
        remove(selector: Mongo.Selector | Mongo.ObjectID | string, callback?: Function): number;
        update(selector: Mongo.Selector | Mongo.ObjectID | string, modifier: Mongo.Modifier, options?: {
            multi?: boolean;
            upsert?: boolean;
        }, callback?: Function): number;
        upsert(selector: Mongo.Selector | Mongo.ObjectID | string, modifier: Mongo.Modifier, options?: {
            multi?: boolean;
        }, callback?: Function): { numberAffected?: number; insertedId?: string; };
        _ensureIndex(indexName: string, options?: { [key: string]: any }): void;
    }

    var Cursor: CursorStatic;
    interface CursorStatic {
        new <T>(): Cursor<T>;
    }
    interface Cursor<T> {
        count(): number;
        fetch(): Array<T>;
        forEach(callback: <T>(doc: T, index: number, cursor: Mongo.Cursor<T>) => void, thisArg?: any): void;
        map<U>(callback: (doc: T, index: number, cursor: Mongo.Cursor<T>) => U, thisArg?: any): Array<U>;
        observe(callbacks: Object): Meteor.LiveQueryHandle;
        observeChanges(callbacks: Object): Meteor.LiveQueryHandle;
    }
}
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

No branches or pull requests

1 participant