I am currently in the process of migrating a component from an old Vue project that relies solely on JavaScript to a TypeScript/Vue project, and I have encountered some obstacles along the way.
<script lang="ts">
import { computed, ref } from "vue";
import { defineComponent } from 'vue'
export default defineComponent ({
setup() {
const todo = ref("");
const todos = ref([]);
let id = 0;
const numberOfCompletedTodos = computed(
() => todos.value.filter((todo) => todo.completed).length
);
function addTodo() {
todos.value.push({
id: id,
title: todo.value.trim(),
completed: false,
});
todo.value = "";
id++;
}
function removeTodo(index) {
todos.value.splice(index, 1);
}
...
...
...
</script>
However, the use of ref([]) is resulting in the following errors:
- Argument of type '{ id: number; title: string; completed: boolean; }' is not
assignable to parameter of type 'never'.ts(2345)
- Property 'completed' does not exist on type 'never'.
- Parameter 'index' implicitly has an 'any' type.