I am using Vue 3 (Composition API) with Typescript. Here is my code.
<script setup lang="ts" generic="T">
import { ref, Ref } from "vue";
const props = defineProps<{
myProp: T;
}>();
const model: Ref<T> = ref(props.myProp);
</script>
My IDE (WebStorm 2024.1.2 with Vue Language Server 1.8.27) tells me:
“Vue: Type Ref<UnwrapRef> is not assignable to type Ref
Type UnwrapRef is not assignable to type T”
Is it a bug from the IDE (I would like to be sure before submitting something to YouTrack)?
I tried the following:
const model: Ref<T> = ref(props.myProp) as Ref<T>;
but I get this warning from ESLint: “ESLint: This assertion is unnecessary since it does not change the type of the expression.(@typescript-eslint/no-unnecessary-type-assertion)”.
Arkandias is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.