title: share firestore collection paths across admin and web
body: <p>I'd like to make re-usable functions that get the Firestore Document/Collection reference across web and admin (node.js).</p>
  <p>for example:</p>
  <pre class="lang-js prettyprint-override"><code>getUserDocumentReference(company: string, user: string) {
    return firebase.collection(&quot;companies&quot;)
      .doc(company)
      .collection(&quot;users&quot;)
      .doc(user);
  }
  </code></pre>
  <p>This will reduce errors and coordinate changes across both environments.</p>
  <p><strong>Problem</strong>: Admin imports firestore from <code>firebase-admin</code>, and web imports from <code>firebase</code>.</p>
  <p>I've tried making some class/function where I pass in my <code>firestore</code> reference, but it becomes a pain where I have to declare the return types:</p>
  <pre class="lang-js prettyprint-override"><code>const ref = (
      getUserDocumentReference(&quot;a&quot;, &quot;1&quot;) as 
        firebase.firestore.DocumentReference
      )
      .withConverter(converter)
  </code></pre>
  <p>Is there a smarter/cleaner way to do this without re-inventing the wheel (i.e. somehow passing an array or re-creating paths in a complex way)?</p>
  <hr />
  <p>my current approach:</p>
  <pre class="lang-js prettyprint-override"><code>class FirestoreReferences {
     constructor(firestore: firebase.firestore.Firestore
    | admin.firestore.Firestore) {
        this.firestore = firestore;
    }
  
    getUserDocumentReference(company: string, user: string): FirebaseFirestore.DocumentReference | firebase.firestore.DocumentReference {
       return this.firestore.collection(...).doc(...);
    }
  }
  </code></pre>