Skip to content

Commit c4986c3

Browse files
committed
Delete PartialWithFieldValue and replace it with DeepPartial<WithFieldValue>
1 parent a51c03e commit c4986c3

File tree

14 files changed

+37
-53
lines changed

14 files changed

+37
-53
lines changed

packages/firestore/lite/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export {
6262
UpdateData,
6363
DeepPartial,
6464
WithFieldValue,
65-
PartialWithFieldValue,
6665
SetOptions,
6766
DocumentReference,
6867
Query,

packages/firestore/src/api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ export {
101101
UpdateData,
102102
DeepPartial,
103103
WithFieldValue,
104-
PartialWithFieldValue,
105104
refEqual,
106105
queryEqual
107106
} from './api/reference';

packages/firestore/src/api/reference.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@ export {
2828
UpdateData,
2929
DeepPartial,
3030
WithFieldValue,
31-
PartialWithFieldValue,
3231
refEqual
3332
} from '../lite-api/reference';

packages/firestore/src/api/reference_impl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ import { FieldPath } from '../lite-api/field_path';
4040
import { validateHasExplicitOrderByForLimitToLast } from '../lite-api/query';
4141
import {
4242
CollectionReference,
43+
DeepPartial,
4344
doc,
4445
DocumentData,
4546
DocumentReference,
46-
PartialWithFieldValue,
4747
Query,
4848
SetOptions,
4949
UpdateData,
@@ -278,12 +278,12 @@ export function setDoc<ModelT, SerializedModelT extends DocumentData>(
278278
*/
279279
export function setDoc<ModelT, SerializedModelT extends DocumentData>(
280280
reference: DocumentReference<ModelT, SerializedModelT>,
281-
data: PartialWithFieldValue<ModelT>,
281+
data: DeepPartial<WithFieldValue<ModelT>>,
282282
options: SetOptions
283283
): Promise<void>;
284284
export function setDoc<ModelT, SerializedModelT extends DocumentData>(
285285
reference: DocumentReference<ModelT, SerializedModelT>,
286-
data: PartialWithFieldValue<ModelT>,
286+
data: DeepPartial<WithFieldValue<ModelT>>,
287287
options?: SetOptions
288288
): Promise<void> {
289289
reference = cast<DocumentReference<ModelT, SerializedModelT>>(

packages/firestore/src/api/snapshot.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { FieldPath } from '../lite-api/field_path';
2121
import {
2222
DeepPartial,
2323
DocumentData,
24-
PartialWithFieldValue,
2524
Query,
2625
queryEqual,
2726
SetOptions,
@@ -93,7 +92,7 @@ export interface FirestoreDataConverter<
9392
* `ModelT` into a plain JavaScript object (suitable for writing directly to
9493
* the Firestore database) of type `SerializedModelT`. To use `set()` with
9594
* `merge` and `mergeFields`, `toFirestore()` must be defined with
96-
* `PartialWithFieldValue<ModelT>`.
95+
* `DeepPartial<WithFieldValue<ModelT>>`.
9796
*
9897
* The `WithFieldValue<ModelT>` type extends `ModelT` to also allow
9998
* FieldValues such as {@link (deleteField:1)} to be used as property values.
@@ -107,15 +106,15 @@ export interface FirestoreDataConverter<
107106
* {@link (setDoc:1)}, {@link (WriteBatch.set:1)} and
108107
* {@link (Transaction.set:1)} with `merge:true` or `mergeFields`.
109108
*
110-
* The `PartialWithFieldValue<ModelT>` type extends `Partial<ModelT>` to allow
111-
* FieldValues such as {@link (arrayUnion:1)} to be used as property values.
112-
* It also supports nested `Partial` by allowing nested fields to be
109+
* The `DeepPartial<WithFieldValue<ModelT>>` type extends `Partial<ModelT>` to
110+
* allow FieldValues such as {@link (arrayUnion:1)} to be used as property
111+
* values. It also supports nested `Partial` by allowing nested fields to be
113112
* omitted.
114113
*/
115114
toFirestore(
116-
modelObject: PartialWithFieldValue<ModelT>,
115+
modelObject: DeepPartial<WithFieldValue<ModelT>>,
117116
options: SetOptions
118-
): DeepPartial<SerializedModelT>;
117+
): DeepPartial<WithFieldValue<SerializedModelT>>;
119118

120119
/**
121120
* Called by the Firestore SDK to convert Firestore data into an object of

packages/firestore/src/lite-api/reference.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ export interface DocumentData {
5050
[field: string]: any;
5151
}
5252

53-
/**
54-
* Similar to Typescript's `Partial<T>`, but allows nested fields to be
55-
* omitted and FieldValues to be passed in as property values.
56-
*/
57-
export type PartialWithFieldValue<T> =
58-
| Partial<T>
59-
| (T extends Primitive
60-
? T
61-
: T extends {}
62-
? { [K in keyof T]?: PartialWithFieldValue<T[K]> | FieldValue }
63-
: never);
64-
6553
/**
6654
* Similar to Typescript's `Partial<T>`, but applies recursively to nested
6755
* objects, making their properties optional as well.

packages/firestore/src/lite-api/reference_impl.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ import { validateHasExplicitOrderByForLimitToLast } from './query';
4040
import {
4141
CollectionReference,
4242
doc,
43+
DeepPartial,
4344
DocumentData,
4445
DocumentReference,
45-
PartialWithFieldValue,
4646
Query,
4747
SetOptions,
4848
UpdateData,
@@ -77,7 +77,7 @@ export function applyFirestoreDataConverter<
7777
SerializedModelT extends DocumentData
7878
>(
7979
converter: UntypedFirestoreDataConverter<ModelT, SerializedModelT> | null,
80-
value: WithFieldValue<ModelT> | PartialWithFieldValue<ModelT>,
80+
value: WithFieldValue<ModelT> | DeepPartial<WithFieldValue<ModelT>>,
8181
options?: PublicSetOptions
8282
): PublicDocumentData {
8383
let convertedValue;
@@ -232,12 +232,12 @@ export function setDoc<ModelT, SerializedModelT extends DocumentData>(
232232
*/
233233
export function setDoc<ModelT, SerializedModelT extends DocumentData>(
234234
reference: DocumentReference<ModelT, SerializedModelT>,
235-
data: PartialWithFieldValue<ModelT>,
235+
data: DeepPartial<WithFieldValue<ModelT>>,
236236
options: SetOptions
237237
): Promise<void>;
238238
export function setDoc<ModelT, SerializedModelT extends DocumentData>(
239239
reference: DocumentReference<ModelT, SerializedModelT>,
240-
data: PartialWithFieldValue<ModelT>,
240+
data: DeepPartial<WithFieldValue<ModelT>>,
241241
options?: SetOptions
242242
): Promise<void> {
243243
reference = cast<DocumentReference<ModelT, SerializedModelT>>(
@@ -410,7 +410,7 @@ export function addDoc<ModelT, SerializedModelT extends DocumentData>(
410410

411411
const convertedValue = applyFirestoreDataConverter(
412412
reference.converter,
413-
data as PartialWithFieldValue<ModelT>
413+
data as DeepPartial<WithFieldValue<ModelT>>
414414
);
415415

416416
const dataReader = newUserDataReader(reference.firestore);

packages/firestore/src/lite-api/snapshot.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
DeepPartial,
2929
DocumentData,
3030
DocumentReference,
31-
PartialWithFieldValue,
3231
Query,
3332
queryEqual,
3433
SetOptions,
@@ -102,15 +101,15 @@ export interface FirestoreDataConverter<
102101
* {@link @firebase/firestore/lite#(setDoc:1)}, {@link @firebase/firestore/lite#(WriteBatch.set:1)}
103102
* and {@link @firebase/firestore/lite#(Transaction.set:1)} with `merge:true` or `mergeFields`.
104103
*
105-
* The `PartialWithFieldValue<ModelT>` type extends `Partial<ModelT>` to allow
104+
* The `DeepPartial<WithFieldValue<ModelT>>` type extends `Partial<ModelT>` to allow
106105
* FieldValues such as {@link (arrayUnion:1)} to be used as property values.
107106
* It also supports nested `Partial` by allowing nested fields to be
108107
* omitted.
109108
*/
110109
toFirestore(
111-
modelObject: PartialWithFieldValue<ModelT>,
110+
modelObject: DeepPartial<WithFieldValue<ModelT>>,
112111
options: SetOptions
113-
): DeepPartial<SerializedModelT>;
112+
): DeepPartial<WithFieldValue<SerializedModelT>>;
114113

115114
/**
116115
* Called by the Firestore SDK to convert Firestore data into an object of

packages/firestore/src/lite-api/transaction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ import { getDatastore } from './components';
3333
import { Firestore } from './database';
3434
import { FieldPath } from './field_path';
3535
import {
36+
DeepPartial,
3637
DocumentData,
3738
DocumentReference,
38-
PartialWithFieldValue,
3939
SetOptions,
4040
UpdateData,
4141
WithFieldValue
@@ -148,12 +148,12 @@ export class Transaction {
148148
*/
149149
set<ModelT, SerializedModelT extends DocumentData>(
150150
documentRef: DocumentReference<ModelT, SerializedModelT>,
151-
data: PartialWithFieldValue<ModelT>,
151+
data: DeepPartial<WithFieldValue<ModelT>>,
152152
options: SetOptions
153153
): this;
154154
set<ModelT, SerializedModelT extends DocumentData>(
155155
documentRef: DocumentReference<ModelT, SerializedModelT>,
156-
value: PartialWithFieldValue<ModelT>,
156+
value: DeepPartial<WithFieldValue<ModelT>>,
157157
options?: SetOptions
158158
): this {
159159
const ref = validateReference(documentRef, this._firestore);

packages/firestore/src/lite-api/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import { UpdateData } from './reference';
1919

2020
/**
2121
* These types primarily exist to support the `UpdateData`,
22-
* `WithFieldValue`, and `PartialWithFieldValue` types and are not consumed
23-
* directly by the end developer.
22+
* `WithFieldValue`, and `DeepPartial<WithFieldValue>` types and are not
23+
* consumed directly by the end developer.
2424
*/
2525

2626
/** Primitive types. */

packages/firestore/src/lite-api/user_data_reader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ import { FieldPath } from './field_path';
6464
import { FieldValue } from './field_value';
6565
import { GeoPoint } from './geo_point';
6666
import {
67+
DeepPartial,
6768
DocumentReference,
68-
PartialWithFieldValue,
6969
WithFieldValue
7070
} from './reference';
7171
import { Timestamp } from './timestamp';
@@ -82,7 +82,7 @@ export interface UntypedFirestoreDataConverter<
8282
> {
8383
toFirestore(modelObject: WithFieldValue<ModelT>): SerializedModelT;
8484
toFirestore(
85-
modelObject: PartialWithFieldValue<ModelT>,
85+
modelObject: DeepPartial<WithFieldValue<ModelT>>,
8686
options: SetOptions
8787
): SerializedModelT;
8888
fromFirestore(snapshot: unknown, options?: unknown): ModelT;

packages/firestore/src/lite-api/write_batch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import { getDatastore } from './components';
2626
import { Firestore } from './database';
2727
import { FieldPath } from './field_path';
2828
import {
29+
DeepPartial,
2930
DocumentData,
3031
DocumentReference,
31-
PartialWithFieldValue,
3232
SetOptions,
3333
UpdateData,
3434
WithFieldValue
@@ -92,12 +92,12 @@ export class WriteBatch {
9292
*/
9393
set<ModelT, SerializedModelT extends DocumentData>(
9494
documentRef: DocumentReference<ModelT, SerializedModelT>,
95-
data: PartialWithFieldValue<ModelT>,
95+
data: DeepPartial<WithFieldValue<ModelT>>,
9696
options: SetOptions
9797
): WriteBatch;
9898
set<ModelT, SerializedModelT extends DocumentData>(
9999
documentRef: DocumentReference<ModelT, SerializedModelT>,
100-
data: WithFieldValue<ModelT> | PartialWithFieldValue<ModelT>,
100+
data: WithFieldValue<ModelT> | DeepPartial<WithFieldValue<ModelT>>,
101101
options?: SetOptions
102102
): WriteBatch {
103103
this._verifyNotCommitted();

packages/firestore/test/lite/helpers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ import {
2626
DocumentData,
2727
CollectionReference,
2828
DocumentReference,
29+
DeepPartial,
30+
WithFieldValue,
2931
SetOptions,
30-
PartialWithFieldValue
3132
} from '../../src/lite-api/reference';
3233
import { setDoc } from '../../src/lite-api/reference_impl';
3334
import { FirestoreSettings } from '../../src/lite-api/settings';
@@ -125,7 +126,7 @@ export const postConverter = {
125126

126127
export const postConverterMerge = {
127128
toFirestore(
128-
post: PartialWithFieldValue<Post>,
129+
post: DeepPartial<WithFieldValue<Post>>,
129130
options?: SetOptions
130131
): DocumentData {
131132
if (

packages/firestore/test/lite/integration.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ import {
6565
collectionGroup,
6666
SetOptions,
6767
DocumentData,
68+
DeepPartial,
6869
WithFieldValue,
69-
PartialWithFieldValue,
7070
UpdateData
7171
} from '../../src/lite-api/reference';
7272
import {
@@ -434,7 +434,7 @@ interface MutationTester {
434434
): Promise<void>;
435435
set<ModelT, SerializedModelT extends DocumentData>(
436436
documentRef: DocumentReference<ModelT, SerializedModelT>,
437-
data: PartialWithFieldValue<ModelT>,
437+
data: DeepPartial<WithFieldValue<ModelT>>,
438438
options: SetOptions
439439
): Promise<void>;
440440
update<ModelT, SerializedModelT extends DocumentData>(
@@ -470,7 +470,7 @@ describe('WriteBatch', () => {
470470

471471
set<ModelT, SerializedModelT extends DocumentData>(
472472
ref: DocumentReference<ModelT, SerializedModelT>,
473-
data: PartialWithFieldValue<ModelT>,
473+
data: DeepPartial<WithFieldValue<ModelT>>,
474474
options?: SetOptions
475475
): Promise<void> {
476476
const batch = writeBatch(ref.firestore);
@@ -535,7 +535,7 @@ describe('Transaction', () => {
535535

536536
set<ModelT, SerializedModelT extends DocumentData>(
537537
ref: DocumentReference<ModelT, SerializedModelT>,
538-
data: PartialWithFieldValue<ModelT>,
538+
data: DeepPartial<WithFieldValue<ModelT>>,
539539
options?: SetOptions
540540
): Promise<void> {
541541
return runTransaction(ref.firestore, async transaction => {
@@ -1419,7 +1419,7 @@ describe('withConverter() support', () => {
14191419
describe('nested partial support', () => {
14201420
const testConverterMerge = {
14211421
toFirestore(
1422-
testObj: PartialWithFieldValue<TestObject>,
1422+
testObj: DeepPartial<WithFieldValue<TestObject>>,
14231423
options?: SetOptions
14241424
) {
14251425
return { ...testObj };
@@ -1716,8 +1716,8 @@ describe('withConverter() support', () => {
17161716
}
17171717

17181718
withPartialFieldValueT(
1719-
value: PartialWithFieldValue<T>
1720-
): PartialWithFieldValue<T> {
1719+
value: DeepPartial<WithFieldValue<T>>
1720+
): DeepPartial<WithFieldValue<T>> {
17211721
return value;
17221722
}
17231723

0 commit comments

Comments
 (0)