Not sure if you already found a solution, but this worked for me, so I share this if anyone looking for a solution stumbles upon this post.
I created a set of Vue plugins and wanted to extend TypeScript's typings.
tsconfig.json
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": true,
"sourceMap": true,
"target": "es5",
"module": "es2015",
"outDir": "lib",
"baseUrl": ".",
"paths": {
"vue": [ "node_modules/vue/types/index" ],
"vue-router": [ "node_modules/vue-router/types/index" ],
"vuex": [ "node_modules/vuex/types/index" ],
"axios": [ "node_modules/axios/index" ]
}
},
"compileOnSave": false,
"exclude": [
//"node_modules",
"wwwroot"
]
}
typings / vue-extension.d.ts
/**
* Augment the typings of Vue.js
*/
import Vue from 'vue'
import { AxiosStatic } from "axios"
declare module '../../../node_modules/vue/types/vue' {
interface Vue {
/**Axios HTTP client */
$http: AxiosStatic;
/**
* Check if user belongs to an application role
* @param role single role or array of roles
* @returns True/False
*/
$UserInRole(role: string | string[]): boolean;
/**Executes box widgets (Collapse/Remove) */
$boxWidget(): void;
}
}
user-profile.ts
import Avatar from "../../../node_modules/vue-avatar/index";
import Vue, { ComponentOptions } from "vue";
export default {
name: "user-profile",
components: {
Avatar
},
template: `<div> <avatar round :name="Fullname"></avatar> </div>`,
data() {
return {
user: { "Title": "", "Bio": "" } as VueComp["user"]
}
},
computed: {
Fullname() {
if (this.$store.state.profile.user.Fullname != undefined) {
this.user.Title = this.$store.state.profile.info.Title;
this.user.Bio = this.$store.state.profile.info.Bio;
return this.$store.state.profile.user.Fullname;
}
return "";
}
},
methods: {
Save() {
// Both $http and component's data extended from 'VueComp'
let vm = this as VueComp;
vm.$http.post("api/account/aboutme", vm.user)
.then(() => {
let info = {
Title: vm.user.Title,
Bio: vm.user.Bio
};
//write back to store
vm.$store.commit("profile/Info", info);
});
}
},
mounted() {
// $boxWidget extended from 'vue-extension.d.ts'
let vm = this as Vue;
vm.$boxWidget();
}
} as ComponentOptions<any>
interface VueComp extends Vue {
user: { Title?: string, Bio?: string }
}