vue/types/test/augmentation-test.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
840 B
TypeScript
Raw Normal View History

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