Skip to content

Commit

Permalink
fix(types): fix $children and $root instance types
Browse files Browse the repository at this point in the history
fix #12655
  • Loading branch information
yyx990803 committed Jul 15, 2022
1 parent cdd2df6 commit 52a5979
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions types/test/v3/define-component-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,7 @@ defineComponent({
this.$on('foo', () => {})
this.$ssrContext
this.$isServer
this.$children[0].$root.$children
return h('div', {}, [...this.$slots.default!])
}
})
1 change: 1 addition & 0 deletions types/test/vue-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Test extends Vue {
this.$isServer
this.$ssrContext
this.$vnode
this.$root.$children[0].$children[0]
}

// test property reification
Expand Down
10 changes: 6 additions & 4 deletions types/vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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
Expand Down

0 comments on commit 52a5979

Please sign in to comment.