vue2/types/test/augmentation-test.ts

47 lines
740 B
TypeScript
Raw Normal View History

import Vue from "../index";
2016-09-22 00:45:40 +08:00
declare module "../vue" {
// add instance property and method
interface Vue {
$instanceProperty: string;
$instanceMethod(): void;
}
// add static property and method
interface VueConstructor {
staticProperty: string;
staticMethod(): void;
2016-09-22 00:45:40 +08:00
}
}
// augment ComponentOptions
declare module "../options" {
interface ComponentOptions<V extends Vue> {
foo?: string;
}
}
const vm = new Vue({
props: ["bar"],
2016-09-22 00:45:40 +08:00
data: {
a: true
},
foo: "foo",
methods: {
foo() {
this.a = false;
}
},
computed: {
BAR(): string {
return this.bar.toUpperCase();
}
}
2016-09-22 00:45:40 +08:00
});
vm.$instanceProperty;
vm.$instanceMethod();
Vue.staticProperty;
Vue.staticMethod();