I have this code which works perfectly fine on my localhost. But Typescript throws me an error Type ‘string’ is not assignable to type Ref<string>.
let placeholderTitle = ref<string>('')
function beforeDragStart() {
placeholderTitle = ''
....
}
Can somedy tell me please what is the problem with this code.
Secondly why this composition api allowes me to asign value straight to the placeholderTitle and placeholdertitle.value = throws me an error?
>Solution :
Being a Ref, placeholderTitle has to be a constant (const instead of let).
Using let allows you to change the content of placeholderTitle, but then Typescript throws legitimately a type error Type 'string' is not assignable to type Ref<string>.
To change the content of a Ref, you have to change its inner .value:
function beforeDragStart() {
placeholderTitle.value = ''
....
}