Skip to content

Commit 2b93e86

Browse files
authoredApr 16, 2021
fix(types): make $refs undefined possible (#11112)
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> ```
1 parent 5260830 commit 2b93e86

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed
 

‎types/vue.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface Vue {
2626
readonly $parent: Vue;
2727
readonly $root: Vue;
2828
readonly $children: Vue[];
29-
readonly $refs: { [key: string]: Vue | Element | Vue[] | Element[] };
29+
readonly $refs: { [key: string]: Vue | Element | (Vue | Element)[] | undefined };
3030
readonly $slots: { [key: string]: VNode[] | undefined };
3131
readonly $scopedSlots: { [key: string]: NormalizedScopedSlot | undefined };
3232
readonly $isServer: boolean;

0 commit comments

Comments
 (0)
Please sign in to comment.