firebase / firebase/firebase-admin-node
[FR]: Why FirestoreDataConverter does not have two generics?
- Lenguaje dominante
- TypeScript
- Estrellas
- 1.7k
- Forks
- 419
- Merge medio
- 3 d 10 h
- PR fusionados (30 d)
- 16
Descripción
**Is your feature request related to a problem? Please describe.**
Add new generics type for fromFirestore in FirestoreDataConverter.
**Describe the solution you'd like**
Hi, I have suggestion about type of FirestoreDataConverter.
Although QueryDocumentSnapshot has generics type, FirestoreDataConverter has no generics except T.
Colud you add generics type S for QueryDocumentSnapshot in "fromFirestore" ?
```
export interface FirestoreDataConverter {
/**
* Called by the Firestore SDK to convert a custom model object of type T
* into a plain Javascript object (suitable for writing directly to the
* Firestore database). To use set() with `merge` and `mergeFields`,
* toFirestore() must be defined with `Partial`.
*
* The `WithFieldValue` type extends `T` to also allow FieldValues such
* as `FieldValue.delete()` to be used as property values.
*/
toFirestore(modelObject: WithFieldValue): DocumentData;
/**
* Called by the Firestore SDK to convert a custom model object of type T
* into a plain Javascript object (suitable for writing directly to the
* Firestore database). To use set() with `merge` and `mergeFields`,
* toFirestore() must be defined with `Partial`.
*
* The `PartialWithFieldValue` type extends `Partial` to allow
* FieldValues such as `FieldValue.delete()` to be used as property values.
* It also supports nested `Partial` by allowing nested fields to be
* omitted.
*/
toFirestore(
modelObject: PartialWithFieldValue,
options: SetOptions
): DocumentData;
/**
* Called by the Firestore SDK to convert Firestore data into an object of
* type T.
*/
fromFirestore(snapshot: QueryDocumentSnapshot): T;
}
```
```
export class QueryDocumentSnapshot<
T = DocumentData
> extends DocumentSnapshot {
private constructor();
/**
* The time the document was created.
*/
readonly createTime: Timestamp;
/**
* The time the document was last updated (at the time the snapshot was
* generated).
*/
readonly updateTime: Timestamp;
/**
* Retrieves all fields in the document as an Object.
*
* @override
* @return An Object containing all fields in the document.
*/
data(): T;
}
```
Guía de contribución
Línea de trabajo
Comienza localizando las declaraciones de TypeScript de FirestoreDataConverter y QueryDocumentSnapshot mostradas en el issue; después, sigue sus usos para entender cómo se propaga el tipo del snapshot. El trabajo estará terminado cuando se añada el genérico solicitado para el snapshot de fromFirestore, se conserve el comportamiento existente del converter y se supere la comprobación de tipos o la suite de pruebas correspondiente.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- databases
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100