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

Support union types and optional fields with dot separation on UpdateData #5394

Merged
merged 13 commits into from
Sep 20, 2021

Conversation

thebrianchen
Copy link

Fixes a bug where UpdateData would not recognize optional, dot-separated string fields. See comment for repro details.

@changeset-bot
Copy link

changeset-bot bot commented Aug 27, 2021

🦋 Changeset detected

Latest commit: 073ab9c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@firebase/firestore Minor
firebase Patch
@firebase/firestore-compat Patch

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

@github-actions
Copy link
Contributor

github-actions bot commented Aug 27, 2021

Changeset File Check ✅

  • No modified packages are missing from the changeset file.
  • No changeset formatting errors detected.

@google-oss-bot
Copy link
Contributor

Size Analysis Report

Affected Products

No changes between base commit (509c18f) and head commit (6397387).

'@firebase/firestore': minor
---

Fixed a bug where UpdateData did not recognize optional, dot-separated string fields
Copy link
Contributor

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!

@svailla4
Copy link

svailla4 commented Sep 2, 2021

How do we use updateData in firebase-admin? @thebrianchen

AddPrefixToKeys<K, UpdateData<T[K]>>
: // TypedUpdateData is always a map of values.
never;
// Union with `undefined` to allow for optional nested fields
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outdated

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks

@thebrianchen thebrianchen changed the title Support optional fields with dot separation on UpdateData Support union types and optional fields with dot separation on UpdateData Sep 9, 2021
@@ -1542,6 +1542,108 @@ describe('withConverter() support', () => {
});
});

it('supports optional fields', () => {
Copy link
Contributor

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?

Copy link
Author

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>
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to <K,V>

packages/firestore/src/lite-api/reference.ts Show resolved Hide resolved
*
* See https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types
*/
export type ChildUpdateFields<K extends string, V> =
Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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.

@Feiyang1 Feiyang1 assigned thebrianchen and unassigned Feiyang1 Sep 20, 2021
@thebrianchen thebrianchen merged commit f78ceca into master Sep 20, 2021
@thebrianchen thebrianchen deleted the bc/fix-update-data branch September 20, 2021 23:22
@google-oss-bot google-oss-bot mentioned this pull request Sep 21, 2021
@firebase firebase locked and limited conversation to collaborators Oct 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: firestore doc-changes PRs that affect docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants