Skip to content

v-else-if does not report TS error in some cases #5157

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
rasmus0201 opened this issue Jan 31, 2025 · 0 comments · Fixed by #5158
Closed

v-else-if does not report TS error in some cases #5157

rasmus0201 opened this issue Jan 31, 2025 · 0 comments · Fixed by #5158
Labels
good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first 🔨 p3-minor-bug

Comments

@rasmus0201
Copy link

Vue - Official extension or vue-tsc version

2.2.0

VSCode version

1.96.4

Vue version

3.5.13

TypeScript version

5.7.2

System Info

package.json dependencies

{
  "dependencies": {
    "vue": "^3.5"
  },
  "devDependencies": {
    "@types/node": "^22.10.1",
    "@vitejs/plugin-vue": "^5.0.4",
    "eslint": "^9.15.0",
    "prettier": "^3.2.5",
    "typescript": "^5.7.2",
    "vite": "^6.0.4",
    "vue-tsc": "^2.1.10"
  }
}

(only a portion of our dependencies, but should be representative)

Steps to reproduce

<script setup lang="ts">
import { ref } from "vue";

type Presentation = {
  source: "local" | "remote";
  stream: MediaStream;
};

const isPresentationPrimary = ref<boolean>(true);

const presentation = ref<Presentation | undefined>();
</script>

<template>
  <div>
    <p v-if="!isPresentationPrimary">Presentation is not primary</p>

    <!-- This does not work (missing TS error): -->
    <p v-else-if="presentation.stream && isPresentationPrimary">Show presentation as primary, if it exists</p>

    <!-- This works (gives TS error): -->
    <!-- <p v-else-if="presentation.stream">Show presentation as primary, if it exists</p> -->
  </div>
</template>
  1. Use the snippet, notice that in VS Code and vue-tsc, you won't get TS error about presentation possibly being undefined for the v-else-if="presentation.stream && isPresentationPrimary"
  2. Comment out the line, and enable the

    below - notice that you now got an error as expected

What is expected?

vue-tsc should throw an error about presentation possibly being undefined.

What is actually happening?

No errors, compiles just fine

Link to minimal reproduction

https://play.vuejs.org/#eNqVk1Fr2zAQx7/KVQ9tConDyPbiuYFt9GGDbWXJo2Bo9tlRK0tCkp2UNN99J5lkzggdexBId3/d/e502rMP1mZ9hyxnhS+dtAE8hs6CErq54yx4zpZcy9YaF2APDms4QO1MCzd07YZrrsOzRXhw6FEHEaTRcAd7rgG86VyJOXCmTCkUZ/BCe4etCcjZ+yQJDkWbw1espFilA9kPtLgujfYBpB+HfnCyFe6ZMhBJ8csYhUIvJ8F1eDu6ZM9povYM8AU6XWEtNVbLSbxYzIfqqVY6BGytEgHpBFBUsk8b2lroZ7KmvlxdxKJenaWRHrSJNMlbzG0KnyJdzWaw3pCgMjiotsY9waSV3kvdwHoF6JxxtznMZuP0qDwODOMis6GRcH19uWFEttqY7XljhD+iTUHWIAPgTvrgB1BK+DdrRPQwaWRPzBcJo/TfmP9Nc8xQzIfHKOanJ2JTGlJ69Vo22aM3miY5DR9npWmtVOi+2xifBjkfxjL6hFJm+yXZ4uxMj/Zyg+XTBfuj30UbZ6m3rqf5PfmCcA2GwX2/+oY72p+crak6RepXnD/QG9VFxkH2kWaTsEe6RPs5/UGajbW/3wXU/lhUBI3KQ9JzRv/y0yul/8FdZG/TPfpw1MWfPboYkxq4yN5lbxbs8BtRSmP7

Any additional comments?

Even though the v-else-if is verbose in adding the && isPresentationPrimary which is not needed logically, I would assume Typescript / vue-tsc to still complain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first 🔨 p3-minor-bug
Projects
None yet
2 participants