前言
在 Vue3 + TypeScript + pinia 项目中,使用 get() set() 定义计算属性时,出现 '不能将类型“WritableComputedRef<string>”分配给类型“string” ts(2322)' 或 "error TS2322: Type 'WritableComputedRef<string>' is not assignable to type 'string'" 错误
src/components/xxxx.vue(xx,xx): error TS2322: Type 'WritableComputedRef<string>' is not assignable to type 'string'.
讯享网
错误复现
1. xxxx.vue 部分
讯享网<template> <input v-model="textvalue" type="text" /> </template> <script setup lang="ts"> import { computed } from 'vue' // pinia import { useHelloworldStore } from '../stores/helloworldStore' const store = useHelloworldStore() // 报错:不能将类型“WritableComputedRef<string>”分配给类型“string” ts(2322) const textvalue: string = computed({ get() { return store.textvalue }, set(newValue: string) { return store.changeTextvalue(newValue) } }) </script>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/74926.html