retorquere retorquere - 19 days ago 4x
TypeScript Question

Declaring an variable initialized in another file

I have some code that references a variable I know has already been declared in a file loaded before mine as in

if (!Zotero.BetterBibTeX) { ... }

but this gets me "Cannot find name 'Zotero'". Is there a way to signal to the typescript compiler that "Zotero" is declared?


You can add this at the top of the file where you're using Zotero:

declare let Zotero: {
    BetterBibTeX: any;

Then you can use if (!Zotero.BetterBibTeX) { ... } as you like.

If you don't want to have any type checking around the properties on Zotero, you can just declare it as an any type:

declare let Zotero: any;