Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): make $refs undefined possible #11112

Merged
merged 1 commit into from
Apr 16, 2021
Merged

fix(types): make $refs undefined possible #11112

merged 1 commit into from
Apr 16, 2021

Conversation

WORMSS
Copy link
Contributor

@WORMSS WORMSS commented Feb 17, 2020

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

<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>

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe: Typings

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

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>
```
@posva posva changed the title types: make $refs undefined possible fix(types): make $refs undefined possible Apr 7, 2021
@posva posva merged commit 2b93e86 into vuejs:dev Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants