环境:

vue@3.2.41

typescript@4.8.4

代码块:

export function test<T>(){

const v = ref<T[]>([])

return v

}

报错:

导出函数的返回类型具有或正在使用外部模块“"/Users/baixiongsoda/home/code/kfc-next/node_modules/.pnpm/@vue+reactivity@3.2.41/node_modules/@vue/reactivity/dist/reactivity"”中的名称“RawSymbol”,但不能为其命名。ts(4058)

导出函数的返回类型具有或正在使用外部模块“"/Users/baixiongsoda/home/code/kfc-next/node_modules/.pnpm/@vue+reactivity@3.2.41/node_modules/@vue/reactivity/dist/reactivity"”中的名称“ShallowReactiveMarker”,但不能为其命名。ts(4058)

原因:

老版本的ts兼容性有问题

解决方案:

1、升级ts版本

2、

export function test<T>(){

const v = ref([]) as Ref<T[]>

return v

}