fix(types): fix $children and $root instance types

fix #12655
This commit is contained in:
Evan You 2022-07-15 16:52:27 +08:00
parent cdd2df6171
commit 52a59790a5
3 changed files with 8 additions and 4 deletions

View File

@ -1148,6 +1148,7 @@ defineComponent({
this.$on('foo', () => {})
this.$ssrContext
this.$isServer
this.$children[0].$root.$children
return h('div', {}, [...this.$slots.default!])
}
})

View File

@ -16,6 +16,7 @@ class Test extends Vue {
this.$isServer
this.$ssrContext
this.$vnode
this.$root.$children[0].$children[0]
}
// test property reification

10
types/vue.d.ts vendored
View File

@ -35,6 +35,8 @@ export interface CreateElement {
): VNode
}
type NeverFallback<T, D> = [T] extends [never] ? D : T
export interface Vue<
Data = Record<string, any>,
Props = Record<string, any>,
@ -47,10 +49,10 @@ export interface 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<Vue>
readonly $parent: NeverFallback<Parent, Vue>
readonly $root: NeverFallback<Root, Vue>
readonly $children: NeverFallback<Children, Vue[]>
readonly $options: NeverFallback<Options, ComponentOptions<Vue>>
$emit: Emit
// Vue 2 only or shared