Subscribe on changes!

A same name prop and variable will show wrong type

avatar
Apr 10th 2022

Version

3.2.31

Reproduction link

stackblitz.com

Steps to reproduce

  1. Open reproduction.
  2. Hover a of (new Comp()).a inside src/components/Foo.ts.

What is expected?

It shows string.

What is actually happening?

It shows never.


When a prop and a variable returned from setup has the same name, the variable returned from setup has higher precedence than a prop. This can be confirmed by the fact that 55: is rendered instead of 55 in the reproduction.

related: https://github.com/johnsoncodehk/volar/issues/1142

avatar
Jun 5th 2022

I can confirm this too. Furthermore, in @sapphi-red's example if you define the type of a the returned type is an intersection of the two types. See updated example here.

I also think it is good to mention it somewhere in the docs that local variables inside the setup() function have higher precedence than props.