Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unset values default to null #1769

Open
2 tasks done
s314cy opened this issue Jan 30, 2024 · 3 comments
Open
2 tasks done

Unset values default to null #1769

s314cy opened this issue Jan 30, 2024 · 3 comments
Labels
breaking-changes Introducing new BREAKING CHANGES enhancement New feature or request question Further information is requested

Comments

@s314cy
Copy link

s314cy commented Jan 30, 2024

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

  • Would you be willing to help implement this feature?

Final checks

@s314cy
Copy link
Author

s314cy commented Jan 30, 2024

Probably something to investigate: attributes default to null, but it seems that relations default to undefined 🤔

@CodeDredd CodeDredd added enhancement New feature or request question Further information is requested breaking-changes Introducing new BREAKING CHANGES and removed pending triage labels May 5, 2024
@CodeDredd
Copy link
Owner

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.

@MartinX3
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-changes Introducing new BREAKING CHANGES enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants