I have a small .js file using Vue that I want to be type-checked with the TypeScript compiler:
function main() {
new Vue({
el: 'ts-message',
template: '<div>Hello</div>',
});
}
If I try to typecheck it with tsc, the compiler complains it cannot find the declaration for Vue even though I have the vue npm package installed:
$ tsc --allowJs --checkJs --noEmit src/main.js
src/main.js:6:9 - error TS2304: Cannot find name 'Vue'.
6 new Vue({
~~~
How do I tell the TypeScript compiler to auto-detect the Vue global object or to import it explicitly in the JS file?
Other things I tried
If this main.js file is renamed to main.ts and I add the following line to the top, then the TypeScript compiler succeeds:
import Vue from "vue";
Unfortunately I need to typecheck JavaScript files specifically and I cannot add such a line to the top of a JavaScript file, since browsers do not recognize that kind of import syntax.