我正在将js代码转换为typescript(angular 1到2)......痛苦的操作!
if (_usersDatabase.updateReplication == null) {
下方的行会导致打字稿错误:
Typescript Error
Property 'updateReplication' does not exist on type 'Database<{}>'.
。它是为了检查函数是否已经定义。
我怎么能为打字稿写这个?
import { MigrationService } from '../providers/migration-service';
import { CouchConstants } from '../couch-constants';
import * as PouchDB from 'pouchdb';
@Injectable()
export class UsersDatabase {
constructor(
private storageService: LocalStorageService
, private UtilsService: UtilsService
, private MigrationService: MigrationService
) {
'use strict';
var _usersDatabase = new PouchDB(CouchConstants.COUCHDB_USERS_DB_NAME);
if (_usersDatabase.updateReplication == null) {
_usersDatabase.updateReplication = function (newDocsIds) {
答案 0 :(得分:5)
'use strict';
使用this
访问他们的方法和变量。
@Injectable()
export class UsersDatabase {
private _usersDatabase : any;
constructor(
private storageService: LocalStorageService
, private UtilsService: UtilsService
, private MigrationService: MigrationService
) {
this._usersDatabase = new PouchDB(CouchConstants.COUCHDB_USERS_DB_NAME);
if (this._usersDatabase.updateReplication == null) {
this._usersDatabase.updateReplication = function (newDocsIds) {
}
}
}