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

Conditional types with v-if are not working through variables #4664

Closed
AdrianFahrbach opened this issue Aug 8, 2024 · 1 comment
Closed
Labels
duplicate This issue or pull request already exists

Comments

@AdrianFahrbach
Copy link

Vue - Official extension or vue-tsc version

v2.0.28

VSCode version

1.92.0

Vue version

3.4.36

TypeScript version

5.5.4

System Info

System:
    OS: macOS 14.6
    CPU: (11) arm64 Apple M3 Pro
    Memory: 74.70 MB / 18.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.15.0 - ~/.nvm/versions/node/v20.15.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.15.0/bin/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v20.15.0/bin/npm
  Browsers:
    Chrome: 127.0.6533.100
    Safari: 17.6
    Safari Technology Preview: 18.0

Steps to reproduce

  1. Create a prop with a conditional type where on of the types has an additional property
  2. Check for these conditional types in a variable
  3. Add two elements with v-if that access the additional property. On of them filters the correct type directly in the template and one does it through the previously created variable.
  4. One of them should throw an "Property x does not exist on type [...]" error

What is expected?

Conditional types should be working even when I'm using a variable to check them.

What is actually happening?

Conditional types are only detected correctly if I do everything in the template.

Link to minimal reproduction

No response

Any additional comments?

CleanShot 2024-08-08 at 10 20 11@2x

<template>
  <p v-if="blok.component === 'with-text'">
    {{ blok.text }}
  </p>
  <p v-if="isWithText">
    {{ blok.text }}
  </p>
</template>

<script lang="ts" setup>
interface WithText {
  component: 'with-text'
  text: string
}

interface WithoutText {
  component: 'without-text'
}

const props = defineProps<{ blok: WithText | WithoutText }>()

const isWithText = props.blok.component === 'with-text'
</script>
@KazariEX
Copy link
Collaborator

KazariEX commented Aug 8, 2024

Duplicate of #4629

@davidmatter davidmatter added duplicate This issue or pull request already exists and removed pending triage labels Aug 8, 2024
@davidmatter davidmatter closed this as not planned Won't fix, can't repro, duplicate, stale Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants