-
Notifications
You must be signed in to change notification settings - Fork 904
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
Support union types and optional fields with dot separation on UpdateData #5394
Conversation
🦋 Changeset detectedLatest commit: 073ab9c The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Changeset File Check ✅
|
Size Analysis Report |
.changeset/clean-cameras-check.md
Outdated
'@firebase/firestore': minor | ||
--- | ||
|
||
Fixed a bug where UpdateData did not recognize optional, dot-separated string fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this goes straight into release notes, I'd suggest UpdateData
as a literal, and a period. Otherwise LGTM, thanks!
How do we use updateData in firebase-admin? @thebrianchen |
…sdk into bc/fix-update-data
AddPrefixToKeys<K, UpdateData<T[K]>> | ||
: // TypedUpdateData is always a map of values. | ||
never; | ||
// Union with `undefined` to allow for optional nested fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks
083ab52
to
160423a
Compare
@@ -1542,6 +1542,108 @@ describe('withConverter() support', () => { | |||
}); | |||
}); | |||
|
|||
it('supports optional fields', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test for null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
*/ | ||
export type ChildUpdateFields<T1, K extends string> = | ||
// Only allow nesting for map values | ||
T1 extends Record<string, unknown> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better name than T1? Reminds me of TI-89
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to <K,V>
…sdk into bc/fix-update-data
* | ||
* See https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types | ||
*/ | ||
export type ChildUpdateFields<K extends string, V> = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks identical to the initial implementation. What has changed that adds the support for optional fields?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an excerpt from the documentation link:
Conditional types in which the checked type is a naked type parameter are called distributive conditional types. Distributive conditional types are automatically distributed over union types during instantiation. For example, an instantiation of T extends U ? X : Y with the type argument A | B | C for T is resolved as (A extends U ? X : Y) | (B extends U ? X : Y) | (C extends U ? X : Y).
Here's a TS playground link that shows the before and after.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the example! Now it makes sense to me.
Fixes a bug where
UpdateData
would not recognize optional, dot-separated string fields. See comment for repro details.