I'm writing vanilla Javascript and trying to use TS type checking in VSCode by specifying the checkJs
flag. (This has been something of an adventure over the past week!)
My project uses ES6 modules bundled by Webpack / Babel; the entry point (app.js
) exports a global variable:
var viewer;
viewer = ...
window.viewer = viewer;
I tell other modules about this variable so eslint
won't bother me:
/* global viewer */
var val = viewer.val;
This works fine, but now the TS checker is complaining
[js] Cannot find name 'viewer'.
How can I tell the TS compiler that I've defined this outside of the current file? Does TS need to be updated to respect the eslint global
comment, or maybe it has its own comment directive syntax?
TypeScript definitely does not respect the eslint note, since it is a comment. For telling TS that an external variable is available, you could simply write declare let viewer: any;
(or with const
instead of let
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With