在我Ionic2的应用程序,我建立了一个供应商注入PouchDB设计文档。
但是,我得到这个打字稿错误:
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(
) {
}
}
这是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 {
...