vue-tsc
doesn't properly narrow discriminated unions in template
#4629
Labels
vue-tsc
doesn't properly narrow discriminated unions in template
#4629
Vue - Official extension or vue-tsc version
vue-tsc version: 2.0.29
VSCode version
N/A - Using
vue-tsc
from cliVue version
3.4.34
TypeScript version
5.4.5
System Info
Steps to reproduce
pnpm type-check
What is expected?
In
ReproComponent.vue
, there should be no errors. The type is defined to be either{ text: string; subheading: { text: string } }
or{ text?: undefined; subheading?: undefined }
.So if
text
is defined,subheading
will definitely be defined.On line 17 we check if truthy and only then do we use the value from
subheading
. According to the types,subheading
cannot be undefined, because we already checkedtext
.This error only occurs in the template, not in the script tag. You can see on line 11 we do the same thing but this time with no error.
Furthermore, when using the component we don't get an error when defining
text
, without definingsubheading
. You can see this inApp.vue
.What is actually happening?
There's an error on line 21, where we use
subheading
:Link to minimal reproduction
https://github.com/MikeBellika/union-type-repro
Any additional comments?
No response
The text was updated successfully, but these errors were encountered: