@@ -101,7 +101,7 @@ toFirestore(modelObject: PartialWithFieldValue<AppModelType>, options: SetOption
101
101
Simple Example
102
102
103
103
` ` ` typescript
104
- const numberConverter: FirestoreDataConverter<number, {value: number}> = {
104
+ const numberConverter = {
105
105
toFirestore(value: WithFieldValue<number>) {
106
106
return { value };
107
107
},
@@ -152,19 +152,19 @@ interface PostDbModel {
152
152
lut: Timestamp;
153
153
}
154
154
155
- // The ` PostConverter ` implements ` FirestoreDataConverter < AppModelType , DbModelType > `
156
- // and specifies how the Firestore SDK can convert ` Post ` objects to ` PostDbModel `
155
+ // The ` PostConverter ` implements ` FirestoreDataConverter ` and specifies
156
+ // how the Firestore SDK can convert ` Post ` objects to ` PostDbModel `
157
157
// objects and vice versa.
158
158
class PostConverter implements FirestoreDataConverter<Post, PostDbModel> {
159
- toFirestore(post: WithFieldValue<Post>) {
159
+ toFirestore(post: WithFieldValue<Post>): WithFieldValue<PostDbModel> {
160
160
return {
161
161
ttl: post.title,
162
162
aut: this._autFromAuthor(post.author),
163
163
lut: this._lutFromLastUpdatedMillis(post.lastUpdatedMillis)
164
164
};
165
165
}
166
166
167
- fromFirestore(snapshot: QueryDocumentSnapshot, options: SnapshotOptions) {
167
+ fromFirestore(snapshot: QueryDocumentSnapshot, options: SnapshotOptions): Post {
168
168
const data = snapshot.data(options) as PostDbModel;
169
169
const author = ` $ {data .aut .firstName } $ {data .aut .lastName }` ;
170
170
return new Post(data.ttl, author, data.lut.toMillis());
@@ -209,7 +209,7 @@ async function advancedDemo(db: Firestore): Promise<void> {
209
209
});
210
210
211
211
// The TypeScript compiler will fail to compile if the ` data ` argument to
212
- // ` setDoc ()` is _not_ be compatible with ` WithFieldValue <Post >` . This
212
+ // ` setDoc ()` is _not_ compatible with ` WithFieldValue <Post >` . This
213
213
// type checking prevents the caller from specifying objects with incorrect
214
214
// properties or property values.
215
215
// @ts-expect-error "Argument of type { ttl: string; } is not assignable
@@ -234,15 +234,15 @@ async function advancedDemo(db: Firestore): Promise<void> {
234
234
// ` PostDbModel ` . Similar to ` setDoc ()` , since the ` data ` argument is typed
235
235
// as ` WithFieldValue <PostDbModel >` rather than just ` PostDbModel ` , this
236
236
// allows properties of the ` data ` argument to also be those special
237
- // Firestore values, like as ` arrayRemove ()` , ` deleteField ()` , and
237
+ // Firestore values, like ` arrayRemove ()` , ` deleteField ()` , and
238
238
// ` serverTimestamp ()` .
239
239
await updateDoc(documentRef, {
240
240
'aut.firstName': 'NewFirstName',
241
241
lut: serverTimestamp()
242
242
});
243
243
244
244
// The TypeScript compiler will fail to compile if the ` data ` argument to
245
- // ` updateDoc ()` is _not_ be compatible with ` WithFieldValue <PostDbModel >` .
245
+ // ` updateDoc ()` is _not_ compatible with ` WithFieldValue <PostDbModel >` .
246
246
// This type checking prevents the caller from specifying objects with
247
247
// incorrect properties or property values.
248
248
// @ts-expect-error "Argument of type { title: string; } is not assignable
0 commit comments