在我的Ionic2应用程序中,我构建了一个提供程序来注入PouchDB设计文档。
但是我收到了这个TypeScript错误:
Typescript Error
Cannot find name 'emit'.
src/providers/design-docs.ts
if (user.location) {
emit(user._id, user.email, user.location);
我不确定将设计文档放在提供程序中的最佳做法,所以我想知道该怎么做。
这是提供者:
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(
) {
}
}
答案 0 :(得分:0)
这是CouchDB的不良做法(请参阅:https://github.com/pouchdb/pouchdb/issues/4624)。要解决此问题,您只需声明发射函数(如@Phonolog在他的评论中所述)。
因此,在发出呼叫之前,请先进行以下操作:
Import { Injectable } from '@angular/core';
declare function emit (val: any);
declare function emit (key: any, value: any);
@Injectable() export class DesignDocs {
...