augmentation-test.ts 840 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import Vue, { defineComponent } from '../index'
  2. declare module '../vue' {
  3. // add instance property and method
  4. interface Vue {
  5. $instanceProperty: string
  6. $instanceMethod(): void
  7. }
  8. // add static property and method
  9. interface VueConstructor {
  10. staticProperty: string
  11. staticMethod(): void
  12. }
  13. }
  14. // augment ComponentOptions
  15. declare module '../options' {
  16. interface ComponentOptions<V extends Vue> {
  17. foo?: string
  18. }
  19. }
  20. const vm = new Vue({
  21. props: ['bar'],
  22. data: {
  23. a: true
  24. },
  25. foo: 'foo',
  26. methods: {
  27. foo() {
  28. this.a = false
  29. }
  30. },
  31. computed: {
  32. BAR(): string {
  33. return this.bar.toUpperCase()
  34. }
  35. }
  36. })
  37. vm.$instanceProperty
  38. vm.$instanceMethod()
  39. Vue.staticProperty
  40. Vue.staticMethod()
  41. defineComponent({
  42. mounted() {
  43. this.$instanceMethod
  44. this.$instanceProperty
  45. }
  46. })