Meteor-Community-Packages / mongo-collection-instances

🗂 Meteor package allowing Mongo Collection instance lookup by collection name

Home Page:http://packosphere.com/dburles/mongo-collection-instances

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typescript extending interface

xonuzofa opened this issue · comments

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;
    }
}