3

Suppose you have the following:

class Foo {
  public bar(): void { baz(); }
}

Where baz is the function which exists in JavaScript code loaded into this page, but which does not exist in this project. How do I hint TypeScript compiler that the function just will be there?

(It's still too early to answer my own question, but I already figured that out, or so it seems):

declare function baz():void;

before the class definition should do the trick.

1 Answers1

4

Use ambient declaration :

declare var baz: any;

That will tell Typescript that baz exists somewhere. You can also add params information and return type to have the IDE help

 declare var baz: (params: string) => string;
Stéphane Piette
  • 5,341
  • 6
  • 34
  • 50