diff --git a/types/test/augmentation-test.ts b/types/test/augmentation-test.ts index 77c616f18d7..6e165857893 100644 --- a/types/test/augmentation-test.ts +++ b/types/test/augmentation-test.ts @@ -1,4 +1,4 @@ -import Vue from '../index' +import Vue, { defineComponent } from '../index' declare module '../vue' { // add instance property and method @@ -44,3 +44,10 @@ vm.$instanceMethod() Vue.staticProperty Vue.staticMethod() + +defineComponent({ + mounted() { + this.$instanceMethod + this.$instanceProperty + } +}) diff --git a/types/test/v3/define-component-test.tsx b/types/test/v3/define-component-test.tsx index b982a805787..2d6fca73d75 100644 --- a/types/test/v3/define-component-test.tsx +++ b/types/test/v3/define-component-test.tsx @@ -1143,6 +1143,7 @@ defineComponent({ // https://github.com/vuejs/vue/issues/12628#issuecomment-1177258223 defineComponent({ render(h) { + // vue 2 this.$listeners this.$on('foo', () => {}) this.$ssrContext diff --git a/types/v3-component-public-instance.d.ts b/types/v3-component-public-instance.d.ts index 6c2770f8cf9..a5bf670139f 100644 --- a/types/v3-component-public-instance.d.ts +++ b/types/v3-component-public-instance.d.ts @@ -5,7 +5,7 @@ import { } from './v3-generated' import { UnionToIntersection } from './common' -import { Vue, Vue2Instance, VueConstructor } from './vue' +import { Vue, VueConstructor } from './vue' import { ComputedOptions, MethodOptions, @@ -13,8 +13,7 @@ import { ComponentOptionsMixin, ComponentOptionsBase } from './v3-component-options' -import { EmitFn, EmitsOptions, Slots } from './v3-setup-context' -import { VNode } from './vnode' +import { EmitFn, EmitsOptions } from './v3-setup-context' /** * Custom properties added to component instances in any way and can be accessed through `this` @@ -173,18 +172,19 @@ interface Vue3Instance< Defaults, MakeDefaultsOptional, Options -> extends Vue2Instance { - $data: D - readonly $props: Readonly< - MakeDefaultsOptional extends true - ? Partial & Omit

- : P & PublicProps - > - readonly $root: ComponentPublicInstance | null - readonly $parent: ComponentPublicInstance | null - readonly $emit: EmitFn - readonly $options: Options & MergedComponentOptionsOverride -} +> extends Vue< + D, + Readonly< + MakeDefaultsOptional extends true + ? Partial & Omit

+ : P & PublicProps + >, + ComponentPublicInstance | null, + ComponentPublicInstance, + ComponentPublicInstance[], + Options & MergedComponentOptionsOverride, + EmitFn + > {} type MergedHook void> = T | T[] diff --git a/types/vue.d.ts b/types/vue.d.ts index ccc7702ace6..b57c5016dd3 100644 --- a/types/vue.d.ts +++ b/types/vue.d.ts @@ -35,17 +35,25 @@ export interface CreateElement { ): VNode } -export interface Vue extends Vue2Instance { - readonly $data: Record - readonly $props: Record - readonly $parent: Vue - readonly $root: Vue - readonly $children: Vue[] +export interface Vue< + Data = Record, + Props = Record, + Parent = never, + Root = never, + Children = never, + Options = never, + Emit = (event: string, ...args: any[]) => Vue +> { + // properties with different types in defineComponent() + readonly $data: Data + readonly $props: Props + readonly $parent: Parent extends never ? Vue : Parent + readonly $root: Root extends never ? Vue : Root + readonly $children: Children extends never ? Vue[] : Children readonly $options: ComponentOptions - $emit(event: string, ...args: any[]): this -} + $emit: Emit -export interface Vue2Instance { + // Vue 2 only or shared readonly $el: Element readonly $refs: { [key: string]: Vue | Element | (Vue | Element)[] | undefined