title: NestJS - Casting in DTO?
body: <p>I am trying to create an object in Mongo (via a websockets gateway) with a schema like:</p>
  
  <pre><code>export class Issue extends Document {
    @Prop()
    name: string;
  
    @Prop()
    description: string;
  
    @Prop()
    project: Types.ObjectId;
  }
  </code></pre>
  
  <p>My DTO also refers to the ObjectId type:</p>
  
  <pre><code>import { Types } from 'mongoose';
  
  export class CreateIssueDto {
    readonly name: string;
    readonly description: string;
    readonly project: Types.ObjectId;
  }
  </code></pre>
  
  <p>The <code>@MessageBody()</code> decorator for the gateway seems to pull everything in as a string and thus, the referenced <code>project</code> is stored as a string in mongo.</p>
  
  <p>What is the correct way to cast this to an <code>ObjectId</code>? Is it just to manually parse the message into its constituents and parse that field specifically?</p>