There seems to be an issue with the compatibility between typescript and the current version (4.17.14) of the express-serve-static

Using

"@types/express-serve-static-core": "4.17.13"
, the augmentation of express-serve-static-core is functioning properly:

import { Request, Response, NextFunction } from 'express'
import { PrismaClient } from '@prisma/client'
import express from 'express'

declare module 'express-serve-static-core' {
  interface Request {
    prisma: PrismaClient
  }
}

const bodyParser = require('body-parser')
const app = express()
const port = 8000


const prisma = new PrismaClient()
app.use((req: Request, res: Response, next: NextFunction) => {
  req.prisma = prisma
  next()
})

After updating to

"@types/express-serve-static-core": "4.17.14"
, the express server stops working and displays this error:
Error: Property 'prisma' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs>'.ts(2339)

https://i.sstatic.net/EOk6X.png

Answer №1

After making updates to other packages, the issue was resolved:

    "@types/express": "4.17.9",
    "@types/node": "14.14.10",
    "@types/express-serve-static-core": "4.17.14",

Answer №2

To fix the issue, I upgraded my devDependencies by switching from

"@types/express": "^4.17.0"
to
"@types/express": "^4.17.2"
. I also included a new dependency
"@types/express-serve-static-core": "4.17.20"
, all without updating my current typescript version which remains at
"typescript": "~3.8.3"

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

Error: The function $.cookie() is not defined in Angular2 Typescript

After installing @types/jquery, I updated tsconfig.json to include jquery.cookie in the types section. Visual Studio Code indicates that $.cookie is ready for use, but when I execute my code, an error appears in the console stating that $.cookie() is not ...

Challenges arise when trying to load CSS on an EJS page in conjunction with using res.redirect()

When using Express with EJS, my base route is set as follows: router.get("/", productsData.getProducts); The "productsData" is sourced from my controllers page and the code snippet within that page is as follows: exports.getProducts = (req, res, next) => ...

How to outsmart the TypeScript compiler when integrating a library without type definitions?

Is there a way to deceive the compiler into thinking that certain definitions are being used? My constructor contains: nv.addGraph(()=> {...}) Before my class declaration, I include: public nv:nv; In my model file, I define: export interface nv{ ...

remove an element from a nested array using MongoDB

Greetings everyone! I am currently working on a materials document that contains arrays of articles, each article having an array of details. Here is a snippet from my collection data: { "_id": "62f2404b42556d62e2939466", "code&quo ...

Try skipping ahead to the following spec file even if the initial spec has not been completed yet

I have encountered an issue when trying to execute two spec files for Angular.js. The problem arises when I attempt to run both files consecutively - the browser initially opens for angular.js, then switches to angularCal.js without executing angular.js ...

Error: Unused variable: '_' has been declared but not utilized

While working on my Next.JS project with TypeScript, I encountered an issue when trying to run the build. The error message stated: Type error: '_' is declared but its value is never read. I attempted to resolve this by setting "noUnusedLocals" ...

A guide on utilizing the TypeScript compilerOptions --outDir feature

Recently, I encountered an error message from the compiler stating: Cannot write file 'path/file.json' because it would overwrite input file. After some investigation, most of the solutions suggested using outDir to resolve this issue. Although t ...

Encountering a compilation error while trying to utilize a union type in a function parameter within an

As stated on https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html, it is recommended to utilize multiple types for a parameter in a function (refer to the union part) /* OK */ interface Moment { utcOffset(): number; ...

My application server is indicating that ports 80 and 443 are already in use, however, when checking with the command `netstat -nlp`, it

Attempting to launch my Express server on ports 80 and 443 results in an error stating that they are already in use. EADDRINUSE err Despite this, my Ubuntu server indicates that ports 80 and 443 are not occupied: ubuntu@ip-182-47-78-432:~$ sudo netstat ...

Angular Material's <mat-select> tag allows for the inclusion of an <input> element within it

I am attempting to place an input element inside the mat-select tag of the Angular Material element. However, I am facing an issue where I cannot input any text into the input field inside the select element. Below is the code I am using to search for elem ...

Node.js Express returning a 404 error

I am currently in the process of developing an express application Here is the content of my app.js file: var express = require('express'); var path = require('path'); var favicon = require('serve-favicon'); var logger = req ...

Using CreateMany within a Prisma Create query

Hello, I have been working on implementing a create statement that accepts an array of another model. Below are my schemas: model House { id String @id createdAt DateTime @default(now()) updatedAt DateTime @updatedAt property_name String ...

Encountering a tuple type TypeScript error with a spread argument is far too frequent an occurrence

Encountering this error is becoming a frequent occurrence for me, and I am currently unable to resolve it. src/graphics.ts:105:55 - error TS2556: A spread argument must either have a tuple type or be passed to a rest parameter. 105 _queue.forEach((_ ...

How can you initialize Boostrap components or Materialize css in Angular 5 without using any external libraries?

I am a beginner exploring the world of Typescript and Angular. I am curious about how to initialize Bootstrap elements in an Angular-friendly manner without using the ngx-Bootstrap wrapper. For instance, if I wish to initiate a Bootstrap carousel. As per ...

WebStorm is not implementing the exclude option as specified in the tsconfig.json file

Is there a way to exclude a directory from TypeScript compilation in WebStorm? Despite specifying the exclusion in the tsconfig.json file, it seems that WebStorm doesn't respect the setting and compiles everything in the root directory. However, runn ...

Issues with data communication in AJAX and Node JS/Express post requests

I'm currently exploring Node.js and I'm running into an issue with app.post. Everything seems to be working fine, as I can see the console log whenever the action is executed. However, the data sent by AJAX from main.js does not seem to be receiv ...

The 'undefined' type cannot be assigned to the 'never' type

interface A { name?: string age: number } var a: A = { name: '', age: 23 } var result:A = (Object.keys(a) as Array<keyof A>).reduce((prev, key) => { if (a[key] || a[key] === 0) { prev[key] = a[key] // an error was reporte ...

Transform nested properties of an object into a new data type

I created a versatile function that recursively converts nested property values into numbers: type CastToNumber<T> = T extends string ? number : { [K in keyof T]: CastToNumber<T[K]> }; type StringMap = { [key: string]: any }; const castOb ...

In the production mode, Webpack doesn't compile any code

I recently followed the typescript guide at https://webpack.js.org/guides/typescript/ After running webpack in "production" mode, I noticed that it emitted very minimal output. Below is the code from my src/index.ts file: export function foo() { return ...

create a fresh variable instead of appending it to the current object

I'm encountering an issue where a new array is supposed to be added on callback using props, but instead an empty variable is being added. Here's the code snippet: const [data, setData] = useState({ title: "", serviceId: "", serviceNa ...