检查打字稿中是否存在函数



我正在将js代码转换为打字稿(角度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) {
  • 无需在打字稿文件中使用'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) {
            }
     }
    }
    

相关内容

  • 没有找到相关文章

最新更新