Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

396
Vistas
TypeScript, Promise and Interface

I recently started using TypeScript, but I'm stuck in one place and can't find a solution to one problem. Can you answer? How to shorten the code and get rid of the creation of an empty intermediate class PaginatedUserDTO ?

file: paginated-user.dto.ts

export class PaginatedUserDTO extends Paginated(UserDTO) {}

file: user.service.ts

async find(filter?: findArgs): Promise<PaginatedUserDTO> {
    const { first, after, last, before, find } = filter;
    const query = this.User.find(find);
    
    return paginate(query, filter); 
}

I tried writing something like:

async find(filter?: findArgs): Promise<Type extends Paginated(BusStopDTO)> {
    ...
}

But it didn't work.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

If I understood correctry, Paginated<T>(classRef: Type<T>) returns Type<IPaginatedType<T>>, so you may try something like

async find(filter?: findArgs): Promise<Type<IPaginatedType<BusStopDTO>>> {
    ...
}

Comment me if it didn't work

about 4 years ago · Juan Pablo Isaza Denunciar

0

Thank you! Yes, it works. But I'm still unable to change the parameter of the Query() decorator. It's part of @nestjs/graphql, I'll try to google it for a solution.

file: user.resolve.ts

@Query(() => PaginatedUserDTO)
async find(@Args() filter?: findArgs) : Promise<IPaginatedType<UserDTO>> {
    return this.userService.find(filter);
}

file: user.service.ts

async find(filter?: findArgs): Promise<IPaginatedType<UserDTO>> {
    const { first, after, last, before, find } = filter;
    const query = this.userModel.find(find);
    return paginate(query, filter);
}

If I write the following, an error will appear:

file: user.resolve.ts

@Query(() => IPaginatedType<UserDTO>)
async find(@Args() filter?: findArgs) : Promise<IPaginatedType<UserDTO>> {
    return this.userService.find(filter);
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda