user1820686 user1820686 - 16 days ago 7
TypeScript Question

TypeScript: suppress Property does not exist on type

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

Answer

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.

Comments