title: Cast entity to dto
body: <p>Just wondering the best way to convert a NestJS entity object to a DTO.</p>
  
  <p>Lets say I have the following:</p>
  
  <pre><code>import { IsString, IsNumber, IsBoolean } from 'class-validator';
  import { Exclude } from 'class-transformer';
  
  export class PhotoSnippetDto {
    @IsNumber()
    readonly id: number;
  
    @IsString()
    readonly name: string;
  
    constructor(props) {
      Object.assign(this, props);
    }
  }
  
  export class Photo {
  
    @IsNumber()
    id: number;
  
    @IsString()
    name: string;
  
    @IsString()
    description: string;
  
    @IsString()
    filename: string;
  
    @IsNumber()
    views: number;
  
    @IsBoolean()
    isPublished: boolean;
  
    @Exclude()
    @IsString()
    excludedPropery: string;
  
    constructor(props) {
      Object.assign(this, props);
    }
  }
  
  @Controller()
  export class AppController {
  
    @Get()
    @UseInterceptors(ClassSerializerInterceptor)
    root(): PhotoSnippetDto {
      const photo = new Photo({
        id: 1,
        name: 'Photo 1',
        description: 'Photo 1 description',
        filename: 'photo.png',
        views: 10,
        isPublished: true,
        excludedPropery: 'Im excluded'
      });
  
      return new PhotoSnippetDto(photo);
    }
  
  }
  </code></pre>
  
  <p>I was expecting the ClassSerializerInterceptor to serialize the photo object to the DTO and return something like this:</p>
  
  <pre><code>{
    id: 1,
    name: 'Photo 1'
  }
  </code></pre>
  
  <p>But I'm getting a response containing all the properties still:</p>
  
  <pre><code>{
    id = 1,
    name = 'Photo 1',
    description = 'Photo 1 description',
    filename = 'file.png',
    views = 10,
    isPublished = true
  }
  </code></pre>
  
  <p>I basically want to strip out all properties that are not defined in the DTO.</p>
  
  <p>I know the ClassSerializerInterceptor works perfectly when using @Exclude(), I was just also expecting it to remove undefined properties also.</p>
  
  <p>I'm curious as to the best way to go about this? I know I could do something like:</p>
  
  <pre><code>@Get('test')
  @UseInterceptors(ClassSerializerInterceptor)
  test(): PhotoSnippetDto {
    const photo = new Photo({
      id: 1,
      name: 'Photo 1',
      description: 'Photo 1 description',
      filename: 'photo.png',
      views: 10,
      isPublished: true,
      excludedPropery: 'Im excluded'
    });
    const { id, name } = photo;
    return new PhotoSnippetDto({id, name});
  }
  </code></pre>
  
  <p>But if I ever want to add another property to the response I'd have to do more than just add the new property to the class.. I'm wondering if there's a better 'Nest way' of doing it.</p>