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

v-if check with union type no longer narrows type since v2.1.8 #4973

Open
Q16solver opened this issue Oct 31, 2024 · 2 comments · May be fixed by #4975
Open

v-if check with union type no longer narrows type since v2.1.8 #4973

Q16solver opened this issue Oct 31, 2024 · 2 comments · May be fixed by #4975
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first 🔨 p3-minor-bug

Comments

@Q16solver
Copy link

Vue - Official extension or vue-tsc version

2.1.8

VSCode version

1.95.0

Vue version

3.5.12

TypeScript version

5.6.3

System Info

No response

package.json dependencies

No response

Steps to reproduce

Hover over the type of the second div with "condition" const and see that it has a type "never"

What is expected?

After checking the first condition with v-if, the second condition type should have type "B"

What is actually happening?

After checking the first condition with v-if, the second condition type no longer narrows the union type, and instead gives "never". This seems to be a regression introduced since v2.1.8 since it has worked in v.2.1.6

Link to minimal reproduction

https://play.vuejs.org/#eNp9kUFPhDAQhf9KM5e9rGzUeFnBBMwe9KBGPTYxBAbsWtqmLUiy8t+dQpblsNkLMPO+ebxpD5AaE3UtwhZiV1hhPHPoW8NkruqEg3ccHrgqtHKe0bMUXmi1ZYxDyoH90TvjkEzlPVfxZnKhGSo8NkbmHqliLC5Fx7orUZHt7MSSJGGrdEVemyWF0uFZNAvoyMabhT2sKSqhlaijvdOK9jkEuzDfGCHRvppgQuts2agELZdS/z6PvSqnP66PQvGNxc8keNue+nvXhx6HN4sObYccZs3ntkY/ybuPF+zpexYbXbaS6AviOzot2xBywrJWlZR7wY1xnxqjrReq/nS73qNyx61C0EAOI8+BbvXxwu6nuLfR3TjH1UDH+NWhDZ50giRE1zcw/AN2jbAd

Any additional comments?

No response

@KazariEX
Copy link
Collaborator

KazariEX commented Nov 1, 2024

This is a TS issue, since you specified an initial value for condition, which has already narrowed its type.

Even if I downgrade to v2.1.6, the behavior still hasn't changed.

@Q16solver
Copy link
Author

Q16solver commented Nov 2, 2024

@KazariEX Yeah you're right, ts seems to have this behaviour for initial values which is interesting, the actual issue that occurred in my own project is from defineProps which has no initial value. I don't know where vue-tsc is in the sfc playground so I created a repro in stackblitz instead where I can control the vue-tsc version

repro link: https://stackblitz.com/edit/github-6c2bqu?file=package.json

Run pnpm typecheck for error with vue-tsc v2.1.8, but it works with v2.1.6, the narrowing from "A" | "B" no longer narrows to "A", and still has "A" | "B" type

@KazariEX KazariEX added bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first 🔨 p3-minor-bug and removed need info labels Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first 🔨 p3-minor-bug
Projects
None yet
2 participants