title: How to define mongoose _id in TypeScript interface?
body: <p>I'm using Mongoose and TypeScript with the interface+<a href="https://mongoosejs.com/docs/advanced_schemas.html#creating-from-es6-classes-using-loadclass" rel="noreferrer">class</a>+schema <a href="https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/mongoose#static-methods" rel="noreferrer">approach</a>.</p>
  
  <p><em>What is the canonical way to store the <code>_id</code> field?</em></p>
  
  <p>I know the db stores it as a bson <code>ObjectID</code>. But I've seen some examples using <code>string</code> and others using mongoose's <code>ObjectId</code>, and then converting between them for various reasons - so I'm unsure which to use.</p>
  
  <pre><code>interface Animal {
    _id: ?type?;        // ?
    name: string;
  }
  </code></pre>
  
  <p>Is it advisable to use</p>
  
  <ul>
  <li><code>string</code></li>
  <li><code>mongoose.Types.ObjectId</code></li>
  <li><code>mongodb.ObjectID</code></li>
  <li><code>bson.ObjectID</code></li>
  </ul>
  
  <p>Also, assuming it is correct to use objectid - I want to avoid taking a dependency on mongoose in the interface file. Is it safe/advisable to use the <code>bson</code> package's <code>ObjectID</code> instead - are they equivalent?</p>