Skip to content

Commit

Permalink
fix(types): make $refs undefined possible (#11112)
Browse files Browse the repository at this point in the history
Added undefined as a return type of $refs as it was quite hard to convince typescript that something COULD be undefined if you type in a ref that doesn't exist,
I also changed the two array statements from `Element[] | Vue[]` to `(Element | Vue)[]` because it's not guaranteed that they are ALL Elements or they are ALL Vue components. (Very likely, yes, but not always)
For example
```html
<template v-for="(a, index) of b">
  <div v-if="index % 2 === 0" ref="test"></div>
  <my-component v-else ref="test"></my-component>
</template>
```
  • Loading branch information
WORMSS authored Apr 16, 2021
1 parent 5260830 commit 2b93e86
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion types/vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface Vue {
readonly $parent: Vue;
readonly $root: Vue;
readonly $children: Vue[];
readonly $refs: { [key: string]: Vue | Element | Vue[] | Element[] };
readonly $refs: { [key: string]: Vue | Element | (Vue | Element)[] | undefined };
readonly $slots: { [key: string]: VNode[] | undefined };
readonly $scopedSlots: { [key: string]: NormalizedScopedSlot | undefined };
readonly $isServer: boolean;
Expand Down

0 comments on commit 2b93e86

Please sign in to comment.