title: TypeORM getRawOne<T> not returning type T
body: <p>I'm working on refactoring a koa api to nest and am kinda stuck on refactoring the queries from native psql to typeorm. I have the following table, view and dto.</p>
  <pre><code>@Entity()
  export class Challenge {
    @PrimaryGeneratedColumn()
    id!: number;
  
    @Column()
    endDate!: Date;
  
    @CreateDateColumn()
    createdAt!: Date;
  }
  
  @ViewEntity({
      expression: (connection: Connection) =&gt; connection.createQueryBuilder()
        .select('SUM(cp.points)', 'score')
        .addSelect('cp.challenge', 'challengeId')
        .addSelect('cp.user', 'userId')
        .addSelect('RANK() OVER (PARTITION BY cp.&quot;challengeId&quot; ORDER BY SUM(cp.points) DESC) AS rank')
        .from(ChallengePoint, 'cp')
        .groupBy('cp.challenge')
        .addGroupBy('cp.user')
  })
  export class ChallengeRank {
    @ViewColumn()
    score!: number;
  
    @ViewColumn()
    rank!: number;
  
    @ViewColumn()
    challenge!: Challenge;
  
    @ViewColumn()
    user!: User;
  }
  
  export class ChallengeResultReponseDto {
      @ApiProperty()
      id!: number;
    
      @ApiProperty()
      endDate!: Date;
  
      @ApiProperty()
      createdAt!: Date;
    
      @ApiProperty()
      score: number;
    
      @ApiProperty()
      rank: number;
  
      test() {
          console.log(&quot;test&quot;)
      }
  }
  </code></pre>
  <p>As the object I want to return is not of any entity type, I'm kinda lost on how to select it and return the correct class. I tried the following:</p>
  <pre><code>this.challengeRepository.createQueryBuilder('c')
          .select('c.id', 'id')
          .addSelect('c.endDate', 'endDate')
          .addSelect('c.createdAt', 'createdAt')
          .addSelect('cr.score', 'score')
          .addSelect('cr.rank', 'rank')
          .leftJoin(ChallengeRank, 'cr', 'c.id = cr.&quot;challengeId&quot; AND cr.&quot;userId&quot; = :userId', { userId })
          .where('c.id = :id', { id })
          .getRawOne&lt;ChallengeResultReponseDto&gt;();
  </code></pre>
  <p>Which returns an object that has the correct fields, but that is not of the class type &quot;ChallengeResultReponseDto&quot;. If I try to call the function &quot;test&quot; the application crashes. Further it feels weird to use the challengeRepository but not return a challenge, should I use the connection or entity manager for this instead?</p>