'Is there anyway to get types interfaces for request, response in Nest.js with Fastify

I am learing Nest.js and on the beging of documentation I read that I can use it not only with express but also with fastify so I setuped up my first project with fastify then I started to read about controllers and I found a problem. For example if I want to get more information about user request i can slightly use @Req req: Reguest and this req is type of Request and it is very easy to get this interface from express based application, yuo only have to install @types/express and then you can inport Request interface from express but how(if it is possible) I can get Request interface if I am using fastify?



Solution 1:[1]

So I lay down that types for fasify are already inside Nest projects because they are coming from @types/node. If you want to use interfaces fro fastify just import them from fastify module. Example:

import { Controller, Get, Query, Req } from '@nestjs/common';
import { AppService } from './app.service';
import { DefaultQuery } from 'fastify';

@Controller('math')
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get('add')
  addTwoNumbers(@Query() query: DefaultQuery): number {
    return this.appService.addTwoNumbers(query.value);
  }
}

If you want to read more about types in fastify visit this link: Fastify Types

Solution 2:[2]

There should be types from @types/fastify that you can install. I believe Fastify uses Request and Reply as Request and Response.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Jay McDoniel