Currently, I am attempting to access a cookie within a NestJS controller.
I have been referencing the documentation found at https://docs.nestjs.com/techniques/cookies#use-with-express-default
Below is my implementation:
import { Controller, Get, Render, Req } from '@nestjs/common';
@Controller()
export class AppController {
@Get()
@Render('home')
getHello(@Req() req: Request) {
return { text: req.cookies['id'] };
}
}
The issue arises when I attempt to access the 'cookies' property on the 'Request' type provided by express. This leads to an error message.
src/app.controller.ts:11:24 - error TS2339: Property 'cookies' does not exist on type 'Request'.
11 return { text: req.cookies['id'] };
~~~~~~~
If I remove the specified 'Request' type from 'req', the code actually executes as intended. However, this solution sacrifices type safety.