Closed tintin10q closed 2 years ago
Let me know if you are able to reproduce this. Weirdly enough I made this code sandbox and in there it did not occur for me:
https://codesandbox.io/s/heuristic-http-okdsqz
Could it maybe have something to do with that I use the persistent pinia plugin and async localforage storage?
thanks for finding that going to look into it after finishing all tests which i refactored all from vuex-orm-next tests and i am 90% done. so much work ^^
@tintin10q sooooo lets see....after adding 182 tests my head is already in standby mode ^^
Woah 182 test what an amazing effort 🤩
But I bet it was super satisfying when they all to passed 😄
182 passed
🍕
yes it was....but most work was already done by Kia King and the contributers. I just made them pinia-orm compatible and migrated to vitest.
@tintin10q i tested your code. And it seems to work after i fixed the double quote marks:
<template>
<button @click="todo.save({text:'Fix TS support', name:'TS Todo'})">Add todo</button>
<button @click="todo.flush()">Clear Todos</button>
<span>{{all_todo_text}}</span>
</template>
<script setup lang="ts">
import { useRepo } from 'pinia-orm'
import Todo from "./models/ToDo";
const todo = useRepo(Todo);
const all_todo_text = computed(() => todo.all().map((t: Todo) => t.text));
</script>
I close this for now....if you need any help just write again
Thanks you for solving the flush thing! This is a very nice thing to have.
Now I have this other problem. I would love to add types to my models to get editor suggestions and the general benefits of Typescript. I tried to add the type definitions as outlined here: https://next.vuex-orm.org/guide/model/decorators.html. When I did this I did get the type information and nice type suggestions in my ide so that works.
But as soon as I defined a type for a field (either with or without a decorator) the field becomes null when queried.
Maybe I am missing something?
Reproduction
Use this simple model:
You can try defining with the decorators or using the commented out fields static method and the type definitions.
Now have a component like this:
Steps to reproduce the behavior
save
).save
Expected behavior
I would expect the values of the model to not be affect (turn to null) by the type definitions.
Actual behavior
When adding type definitions to models the values of the fields turn to null and in the case of decorators the values given in
.save
are ignored. With this the type definitions are not useable.