Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue + TypeScript override `export default Vue`

I am trying to use Vue and TypeScript. I am trying to compile to AMD in my tsconfig.

The type definition that comes with Vue.js states in vue/types/index.d.ts

export default Vue;

However, that causes typescript to compile this:

import Vue as "vue";
export default Vue.extend({ ... });

essentially, into this:

define(["vue"], function(vue) {
  exports.default = vue.default.extend({  ... })
});

Notice, that it believes vue should have a property .default, which it does not. Is there anyway to write a type definition that overrides the default vue type definition that states something like:

export = Vue;

or some flag in tsconfig that tells typescript not to add that .default property to the compiled AMD module?

like image 460
Michael Wilson Avatar asked Oct 29 '18 20:10

Michael Wilson


1 Answers

Enabling the esModuleInterop compiler option will make TypeScript generate code to check for both vue and vue.default at runtime.

As you note, the Vue type declaration is inaccurate, but based on this previous issue, I don't know if a new issue about it will be well received.

like image 149
Matt McCutchen Avatar answered Oct 29 '22 14:10

Matt McCutchen