3

I came across with the following problem with TypeScript:

There is a module, which uses a function myApp.common.anotherFunc() from "old" js code :

module myApp {
    export module helpers {

        export class baseHelper {
            doWork() {
                var m = myApp.common.anotherFunc();
            }
        }
    }
}

As a result typescript compiler shows an error "Property does not exist on type". How can I overcome this problem without rewriting my old functionality in myApp.common ?

P.S. TS version is 2.0 if it matters

user1820686
  • 2,008
  • 5
  • 25
  • 44

1 Answers1

5

Just declare the function for the TypeScript:

declare module myApp.common {
    let anotherFunc: Function;
}

module myApp {
    export module helpers {

        export class baseHelper {
            doWork() {
                var m = myApp.common.anotherFunc();
            }
        }
    }
}

This declaration does not generate any code and you won't see the compiler errors anymore because it knows about the function.

smnbbrv
  • 23,502
  • 9
  • 78
  • 109
  • Thanks, it works correctly. But is it necessary to declare module another way if I got something like myApp.common["propA"]() ? Because in this case compiler exception still exists – user1820686 Nov 17 '16 at 08:37