fix(pinia-orm): accept eager load callback for optional relations#2030
Merged
Conversation
Relations declared with TypeScript optional properties (posts?: Post[]) were not covered by WithKeys and the eager load callback conditionals, because the property type includes undefined. The callback of with(), whereHas() etc. then resolved to '() => void'/'never' and passing a query constraint produced a compile error. fixes #1999
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2030 +/- ##
=======================================
Coverage 99.43% 99.43%
=======================================
Files 82 82
Lines 3022 3022
Branches 530 530
=======================================
Hits 3005 3005
Misses 14 14
Partials 3 3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Jul 19, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
When a relation is declared as an optional property —
— the property type includes
undefined, soWithKeys<M>skipped the key and the callback conditional inwith()/whereHas()/whereDoesntHave()fell through to() => void/never. Passing a query constraint callback then failed to compile (#1999).Fix
WithKeys<T>now strips optionality (-?) and checksNonNullable<T[P]>undefinedin the union (M[T] extends Model | Model[] | null | undefined ? …)UltimateKeyshelperType-only change, no runtime behavior touched.
Tests
New test using an optional
comments?: Comment[]relation with awith()constraint callback — produces 2tscerrors before the fix, compiles clean after (verified withtsc --noEmit; no new errors elsewhere). Full suite green (402 tests).fixes #1999