typescript - Pouchdb med Angular2, kan inte hitta namnet emit


I min Ionic2-app har jag byggt en provider för att injicera PouchDB-design-dokument.

Men jag får detta TypeScript-fel:

Typescript Error
Cannot find name 'emit'.
src/providers/design-docs.ts
if (user.location) {
    emit(user._id, user.email, user.location);

Jag är inte säker på att det är bästa praxis att lägga designdokumenten hos en leverantör, så jag skulle vilja veta vad man ska göra.

Här är leverantören:

import { Injectable } from '@angular/core';


@Injectable()
export class DesignDocs {

    DESIGN_DOCS =
        {
            views:
                    {
                        filters: {
                            byDocIds: function (doc, req) {
                                if (!req.query.docIds)
                                    return false;
                                var docIds = JSON.parse(req.query.docIds);  
                                if (!docIds || !Array.isArray(docIds))
                                    return false;
                                return docIds.indexOf(doc._id) > -1;
                            }
                        },
                        views: {
                            haslocation: {
                                map: function (user) {
                                    if (user.location) {
                                        emit(user._id, user.email, user.location);
                                    }
                                }
                            },
                            email: {
                                map: function (doc) {
                                    emit(doc.email, doc);
                                }
                            },
                            docByEmail: {
                                map: function (doc) {
                                    emit(doc.email);
                                }
                            },
                            emails: {
                                map: function (doc) {
                                    emit(doc.firstName, doc.lastName, doc.email, doc.authVia);
                                }
                            },
                            googleUsers: {
                                map: function (doc) {
                                    if (doc.authVia == "google") {
                                        emit(doc.email, doc);
                                    }
                                }
                            },
                            fbUsers: {
                                map: function (doc) {
                                    if (doc.authVia == "FB") {
                                        emit(doc.email, doc);
                                    }
                                }
                            },
                            namesEmails: {
                                map: function (doc) {
                                    var firstName, lastName, name;
                                    if (doc.authVia == "BL") {
                                        firstName = "";
                                        lastName = "";
                                    }
                                    if (doc.authVia == "google" || doc.authVia == "FB") {
                                        if (doc.name) {
                                            firstName = doc.name;
                                            lastName = "";
                                        } else {
                                            firstName = doc.firstName;
                                            lastName = doc.lastName;
                                        }
                                    }
                                    emit(name, [firstName, lastName, doc.email, doc.authVia]);
                                }
                            }
                        }
                    }
        };

    constructor(

    ) {
    }

}

Svar #1

Detta är en dålig praxis från CouchDB (se: https://github.com/pouchdb/pouchdb/issues/4624). För att åtgärda det behöver du bara deklarera emit-funktionen (som @Phonolog sa i sin kommentar).

Så innan du kallar emit, gör detta:

Import { Injectable } from '@angular/core';

declare function emit (val: any);
declare function emit (key: any, value: any);

@Injectable() export class DesignDocs {
...