Unset values default to null
Describe the feature
When defining a Pinia ORM model in TypeScript, optional fields must be typed as field: type | null because the save method of Pinia ORM repos converts unset values (null, undefined) to null.
However, the usual TypeScript way is declaring an optional field as field?: type, which treats an unset value as undefined. Furthermore, TypeScript's optional chaining (a?.b?.c) and utility types (Required<T>, Partial<T>, etc.) also revolve around the undefined value.
My proposition is to replace the usage of null for unset values with undefined. This seems fairly easy and is rather a matter of acceptance by/relevance to the project.
Additional information
- [X] Would you be willing to help implement this feature?
Final checks
- [X] Check existing discussions and issues.
Probably something to investigate: attributes default to null, but it seems that relations default to undefined 🤔
I think you are right. But changing this, is something for v2 i think. Because it's a huge breaking change. But i could already implement this behaviour with a feature flag.
The optional chaining works with undefined and null
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
If the object accessed or function called using this operator is undefined or null, the expression short circuits and evaluates to undefined instead of throwing an error.