Subscribe on changes!

Watching multiple refs results in a wrong TypeScript assertion in the callback

avatar
Jan 29th 2021

Version

3.0.5

Reproduction link

https://codesandbox.io/s/vue3-provide-inject-example-forked-f5tu1?file=/src/components/HelloWorld.vue

Steps to reproduce

If you hover over the returned values un the callback, you'll see a union type (string | number)[] instead of the correct [string, number] which can be inferred from the watched array

What is expected?

The array to be typed correctly

What is actually happening?

A union type is returned

avatar
Jan 29th 2021

By the way: casting the values as const works, but that seems like a bit of an escape hatch?

watch([foo, bar] as const, ([newFoo, newBar], [oldFoo, oldBar]) => {
avatar
Jan 29th 2021

This seems to work as intended with how TS unions arrays