vuejs / language-tools

⚡ High-performance Vue language tooling based-on Volar.js
https://marketplace.visualstudio.com/items?itemName=Vue.volar
MIT License
5.79k stars 390 forks source link

Type assertions in setup are not narrowed in template #4391

Closed minht11 closed 1 month ago

minht11 commented 4 months ago

After upgrading to vue-tsc 2.0.19 previous code no longer works:

const value: number | undefined = 1

if (!value) {
    throw new Error('Undefined')
}
<Component must-be-number={value} />

I get error

'__VLS_ctx.value' is possibly 'undefined'.

Verified working version 2.0.7

benkroeger commented 1 month ago

especially annoying when injecting a value and throwing if undefined in setup - still getting is possibly 'undefined' for template checks.

const value = inject('value');
if (value === undefined)
  throw new Error('value is undefined');