augmentation-test.ts 727 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import Vue 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()