The 'cookies' property is not found on the 'Request' type

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.

Answer №1

Ensure to include the Request type from the express package (install @types/express). The current one you are utilizing is not associated with it. It is presumed that you are using the default http adapter.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to check the API response status in NextJS13?

Currently, I am experimenting with different methods to handle API HTTP status in my NextJS-13 project but so far nothing has been successful. Note: TypeScript is being used in this project. Below is my code snippet with a static 200 API response and the ...

Comparison between belongsTo and hasMany associations in Sequelize

Consider a scenario where we have a "shirt" table and a "john" table. When using Sequelize, if we define db.john.hasMany(db.shirt), a foreign key is created in the "shirt" table. Similarly, when we use db.shirt.belongsTo(db.john), a foreign key for "joh ...

Determining the typing of a function based on a specific type condition

I have created a unique type structure as shown below: type Criteria = 'Criterion A' | 'Criterion B'; type NoCriteria = 'NO CRITERIA'; type Props = { label?: string; required?: boolean; disabled?: boolean; } & ( | ...

Encountering a hiccup as I attempt to set up a new user through Express NodeJs with Passport integration

I'm encountering an issue while attempting to set up a registration page for users. After trying to make a POST request to save the user in the database, I am getting an error that states TypeError: req.checkBody is not a function. I have also used np ...

Guide on redirecting a React application to the payment success page following the completion of a payment through QR code scanning

I have developed an e-commerce app using PERN (Postgres, Express, React, Node) stack. I am looking to inform users about successful payments by automatically redirecting them to a payment success page after they scan a QR code to make the payment. However ...

Struggling to make EJS button functional on the template

I am currently facing an issue with a loop that populates a webpage with multiple items, each containing an image, text, button, and a unique ID associated with it. Although I have written a function to retrieve the ID and plan name when the button is clic ...

Aliases in Typescript are failing to work properly when used alongside VSCode Eslint within a monorepository

I've incorporated Typescript, Lerna, and monorepos into my current project setup. Here's the structure I'm working with: tsconfig.json packages/ project/ tsconfig.json ... ... The main tsconfig.json in the root directory looks lik ...

The node/express server is throwing an error due to an undefined parameter

What seems to be the issue with my string parameter? var express = require('express'); var app = module.exports = express(); var mongoose = require('mongoose'); var bodyParser = require('body-parser'); var braintree = require ...

The side menu fails to appear when pressed

When using the push method, I am unable to see the side menu. However, it works fine with the setRoot navigation. How can I resolve this issue and display the side menu when using the push method? dashboard.html <ion-col col-9> <ion-searchbar ...

Having trouble receiving a blob response using HttpClient POST request in Angular 9?

I'm encountering an issue while attempting to receive a zip file as a blob from an HTTP POST request. However, the resolved post method overload is not what I expected. const options = { responseType: 'blob' as const }; Observable<Blob ...

Using React.js to Retrieve Data from the Server without AJAX Calls

Currently, I am in the process of creating a web application using Express.js for the back-end and React.js for the front-end. Prior to using React.js, I utilized EJS templating and followed a similar workflow on the back-end as shown below: var express = ...

Error TS2322: You cannot assign a Promise<any> to a string type

Having an issue in my react app where I am attempting to import the img source but encountering an error: TS2322: Type 'Promise<any>' is not assignable to type 'string'. What is the correct way to import an element into a variabl ...

Can you provide details about the launch configuration for pwa-node in VSCode?

When setting up npm debugging in VSCode, I couldn't help but notice that the default launch configuration is labeled as "pwa-node" instead of just "node". Here's what the "Launch via NPM" configuration looks like: And this is what the generated ...

Can a JavaScript object be created in TypeScript?

Looking for a way to utilize an existing JavaScript "class" within an Angular2 component written in TypeScript? The class is currently defined as follows: function Person(name, age) { this.name = name; this.age = age; } Despite the fact that Java ...

What is the best way to create an Express/Connect route that does not affect the session data?

Currently, I am working on a single-page JavaScript application that communicates with Express in the backend. Throughout the app, there are interactions with the backend to update the session, which has a short expiration for security purposes. I am inte ...

Ensuring the inclusion of library licenses in the production build is a crucial step

We have numerous dependencies (node_modules) in our Angular app, which are typically licensed under Apache 2.0 or MIT. From my understanding of the licenses, the production build is considered a "derived work" and we are required to include copyright notic ...

Using async and await for uploading images

I am trying to create a post and upload an image if one is provided. If I successfully upload the image, everything works smoothly. However, if I do not upload an image, I encounter the following error: UnhandledPromiseRejectionWarning: TypeError: Cannot r ...

In relation to the Uncaught Error: Syntax error, an unrecognized expression has been encountered

Recently, I started working on an AngularJS and Node.js application. It's all new to me. In the HTML page, I defined a link as <li><a data-toggle="modal" data-target="#myModal" href="/#/login">Login</a></li>, and then set up th ...

Fetching data from React Router v6 Navigate

When I navigate to a new route, I am encountering an issue with passing state data in TypeScript. The error message says: Property 'email' does not exist on type 'State'." The parent functional component looks like this: naviga ...

Open the CSV document

Why am I receiving an error stating ./vacancy-data.csv cannot be found when attempting to pass the csv file into the csvtojson npm package? The csv file is located in the same directory as the code below: var express = require('express'), route ...