Vue 3.0 配合 typescript 使用 watch 侦听多个源时类型是否有错误?

当我写如下代码时:

import { watch, ref, reactive } from 'vue'

const count = ref<string>('')
const reactiveCount = reactive({
    count: 0
})

watch([count, () => reactiveCount.count], ([newCount, newRefCount]) => {
    // ...
})

观察发现 newCountnewRefCount 的类型均是 string | number

那这样的话只能用 typeof 之后再去使用侦听来的值了吗...

阅读 2.1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题