[Vuejs]-Using typescript module without require()

0👍

I typically work around the issue you ran into by creating globals.d.ts file which is responsible to setting up the global environment that my code expects. In your case something like:

import * as _Vue from "vue";

declare global {
    const Vue: typeof _Vue;
}

This makes it so that the compiler will see a Vue symbol in the global space which is of the same type as what the “vue” module exports.

With the above file, this compiles:

const q = new Vue();

Note that you either will have to use a tsconfig.json. Even an empty one works. (By “empty”, I mean a file that contains only an empty JSON structure: {}.) Or you will have to list all files to compile, including globals.d.ts at the command line.

Leave a comment