Skip to content

Support type narrowing by v-if on template diagnostic #1204

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

Closed
ktsn opened this issue Apr 15, 2019 · 0 comments · Fixed by #1208
Closed

Support type narrowing by v-if on template diagnostic #1204

ktsn opened this issue Apr 15, 2019 · 0 comments · Fixed by #1208

Comments

@ktsn
Copy link
Member

ktsn commented Apr 15, 2019

Like TypeScript's if statement, v-if, v-else-if and v-else should narrow union types which are used in their conditions.

<template>
  <p v-if="!messages">Loading...</p>
  <div v-else> <!-- messages should be narrowed to string[] here -->
    <p v-for="m in messages" :key="m">
      {{ m }}
    </p>
  </div>
</template>

<script lang="ts">
import Vue from 'vue'

export default Vue.extend({
  data() {
    messages: null as string[] | null
  }
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants