@@ -438,6 +438,20 @@ export function deleteDoc<AppModelType, DbModelType extends DocumentData>(
438438 return executeWrite ( firestore , mutations ) ;
439439}
440440
441+ /**
442+ * Add a new document to specified `DocReference` with the given data.
443+ *
444+ * @param reference - A reference to the document to add.
445+ * @param data - An Object containing the data for the new document.
446+ * @returns A `Promise` resolved with a `DocumentReference` pointing to the
447+ * newly created document after it has been written to the backend (Note that it
448+ * won't resolve while you're offline).
449+ * @throws FirestoreError if the document already exists.
450+ */
451+ export function addDoc < AppModelType , DbModelType extends DocumentData > (
452+ reference : DocumentReference < AppModelType , DbModelType > ,
453+ data : WithFieldValue < AppModelType >
454+ ) : Promise < DocumentReference < AppModelType , DbModelType > > ;
441455/**
442456 * Add a new document to specified `CollectionReference` with the given data,
443457 * assigning it a document ID automatically.
@@ -451,10 +465,17 @@ export function deleteDoc<AppModelType, DbModelType extends DocumentData>(
451465export function addDoc < AppModelType , DbModelType extends DocumentData > (
452466 reference : CollectionReference < AppModelType , DbModelType > ,
453467 data : WithFieldValue < AppModelType >
468+ ) : Promise < DocumentReference < AppModelType , DbModelType > > ;
469+ export function addDoc < AppModelType , DbModelType extends DocumentData > (
470+ reference :
471+ | CollectionReference < AppModelType , DbModelType >
472+ | DocumentReference < AppModelType , DbModelType > ,
473+ data : WithFieldValue < AppModelType >
454474) : Promise < DocumentReference < AppModelType , DbModelType > > {
455475 const firestore = cast ( reference . firestore , Firestore ) ;
456476
457- const docRef = doc ( reference ) ;
477+ const docRef =
478+ reference instanceof DocumentReference ? reference : doc ( reference ) ;
458479 const convertedValue = applyFirestoreDataConverter ( reference . converter , data ) ;
459480
460481 const dataReader = newUserDataReader ( reference . firestore ) ;
0 commit comments