Check if a function exists in typescript

I am converting js code to typescript (angular 1 to 2) ... painful operation!

the line below if (_usersDatabase.updateReplication == null) {

results in a typescript error:

Typescript Error
Property 'updateReplication' does not exist on type 'Database<{}>'.

      

... He did to check if the function is defined.

How can I write this for typescript please?

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) {

      

+3


source to share


1 answer


  • Don't need to use 'use strict';

    in typescript File
  • accessing their method and variables with 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) {
    
            }
     }
    }
    
          



+4


source







All Articles