I am trying to create a computed array of type Todo[], but I keep encountering this specific error:
No overload matches this call. Overload 1 of 2, '(getter: ComputedGetter<Todo[]>, debugOptions?: DebuggerOptions | undefined): ComputedRef<Todo[]>', gave the following error. Overload 2 of 2, '(options: WritableComputedOptions<Todo[]>, debugOptions?: DebuggerOptions | undefined): WritableComputedRef<Todo[]>', gave the following error.
This is what I have attempted so far:
todo.ts
export class Todo {
checked: boolean;
text: string
constructor(checked: boolean, text: string) {
this.checked = checked;
this.text = text
}
}
Todos.vue
<script setup lang="ts">
import { computed } from '@vue/reactivity';
import { ref } from 'vue'
import { Todo } from '../todo'
let todos = ref<Todo[]>([]);
const filter = ref<string>('all')
const filteredTodos = computed<Todo[]>(() => {
if(filter.value == "all") return todos;
if(filter.value == "active") return todos.value.filter((item) => !item.checked)
if(filter.value == "completed") return todos.value.filter((item) => item.checked)
})
</script>