I’m new in TypeScript and trying to use it with Vue 3 composition API and provide / inject.
Let's say in parent component A I have something like this:
// Parent component A
import { provide, ref } from 'vue';
import ScoreType from "@/types/Score";
setup() {
..
const score = ref<ScoreType[]>([]);
const updateScore = (val: ScoreType) => {
score.value.push(val);
};
provide('update_score', updateScore);
..
}
...and then want to inject updateScore function in child component B to be able to update values in parent component A (this is what docs recommend). Unfortunately, I get a TS error Object is of type 'unknown'
// Child component B
import { inject } from 'vue';
setup() {
..
const updateScore = inject('update_score');
const checkAnswer = (val: string) => {
updateScore({ /* ScoreType object */ }); // → Object is of type 'unknown'.
}
..
}
What should I do to fix the TypeScript error? I couldn't find any examples about injecting update functions in TS.