title: Sharing typescript interfaces between client and server mongoose model
body: <p>I'm trying to share some base interfaces between the client code and the server code. I'm having problems when using the interfaces to create data models in mongoose.</p>
  
  <p>The problem I have is how to access the document._id property in the client. I can't add _id to the User interface without causing compilation errors and I can't access _id without declaring it.</p>
  
  <p>My project layout:</p>
  
  <pre><code>/src
  -/client
  --/user.service.ts
  -/server
  --/models
  ---/user.model.ts
  -/common
  --/common.d.ts
  </code></pre>
  
  <p>user.service.ts</p>
  
  <pre><code>import { User } from 'common'
  
   deleteUser(user: User): Promise&lt;User&gt; {
     return this.http.delete( 'http://someurl/api/users' + user._id )
       .toPromise()
       .then( resp =&gt; resp.json().data as User )
       .catch( err =&gt; this.errorHandler(err) );
   }
  </code></pre>
  
  <p>user.model.ts</p>
  
  <pre><code>import { model, Schema, Document } from 'mongoose';
  import { User } from 'common';
  
  let UserSchema = new Schema {
    firstName: String,
    lastName: String,
    email: String
  }
  
  export interface UserDocument extends User, Document { }
  
  export var UserModel:Model&lt;UserDocument&gt; = model&lt;UserDocument&gt;('Users', UserSchema);
  </code></pre>
  
  <p>common.d.ts</p>
  
  <pre><code>declare module 'common' {
    export interface User {
      firstName: string;
      lastName: string;
      email: string;
    }
  }
  </code></pre>
  
  <p>Thanks for the help</p>