@@ -20,7 +20,7 @@ import * as firestore from '../../index';
20
20
import { Firestore } from './database' ;
21
21
import { DocumentReference } from './reference' ;
22
22
import { FieldPath } from './field_path' ;
23
- import { tryCast } from './util' ;
23
+ import { cast } from './util' ;
24
24
import { DocumentKey } from '../../../src/model/document_key' ;
25
25
import { Document } from '../../../src/model/document' ;
26
26
import { UserDataWriter } from '../../../src/api/user_data_writer' ;
@@ -60,25 +60,23 @@ export class DocumentSnapshot<T = firestore.DocumentData>
60
60
data ( ) : T | undefined {
61
61
if ( ! this . _document ) {
62
62
return undefined ;
63
- } else {
63
+ } else if ( this . _converter ) {
64
64
// We only want to use the converter and create a new DocumentSnapshot
65
65
// if a converter has been provided.
66
- if ( this . _converter ) {
67
- const snapshot = new QueryDocumentSnapshot (
68
- this . _firestore ,
69
- this . _key ,
70
- this . _document
71
- ) ;
72
- return this . _converter . fromFirestore ( snapshot ) ;
73
- } else {
74
- const userDataWriter = new UserDataWriter (
75
- this . _firestore . _databaseId ,
76
- /* timestampsInSnapshots= */ false ,
77
- /* serverTimestampBehavior=*/ 'none' ,
78
- key => new DocumentReference ( this . _firestore , key )
79
- ) ;
80
- return userDataWriter . convertValue ( this . _document . toProto ( ) ) as T ;
81
- }
66
+ const snapshot = new QueryDocumentSnapshot (
67
+ this . _firestore ,
68
+ this . _key ,
69
+ this . _document
70
+ ) ;
71
+ return this . _converter . fromFirestore ( snapshot ) ;
72
+ } else {
73
+ const userDataWriter = new UserDataWriter (
74
+ this . _firestore . _databaseId ,
75
+ /* timestampsInSnapshots= */ false ,
76
+ /* serverTimestampBehavior=*/ 'none' ,
77
+ key => new DocumentReference ( this . _firestore , key )
78
+ ) ;
79
+ return userDataWriter . convertValue ( this . _document . toProto ( ) ) as T ;
82
80
}
83
81
}
84
82
@@ -119,7 +117,7 @@ export function fieldPathFromArgument(
119
117
if ( typeof arg === 'string' ) {
120
118
return fieldPathFromDotSeparatedString ( methodName , arg ) ;
121
119
} else {
122
- const path = tryCast ( arg , FieldPath ) ;
120
+ const path = cast ( arg , FieldPath ) ;
123
121
return path . _internalPath ;
124
122
}
125
123
}
0 commit comments