question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript: Property 'file' does not exist on type 'Request'

See original GitHub issue

Because the file/s or body attributes (and all the rest) is added in runtime, the Typescript compiler does not recognize them and it fails. So, they should be referenced like this

app.post('/profile', upload.single('avatar'), function (req, res, next) {
  // req['file'] is the `avatar` file
  // req['body'] will hold the text fields, if there were any
})

app.post('/photos/upload', upload.array('photos', 12), function (req, res, next) {
  // req['files'] is array of `photos` files
  // req['body'] will contain the text fields, if there were any
})

Just wanted to point that out. Maybe you can add a comment in the documentation. Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:12
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

45reactions
blakeembreycommented, Oct 15, 2016

I haven’t been writing them, but I could. I just have a simple local definition for myself that looks like this:

export interface MulterFile {
  key: string // Available using `S3`.
  path: string // Available using `DiskStorage`.
  mimetype: string
  originalname: string
  size: number
}

app.get(function (req: express.Request & { files: MulterFile[] }, res: express.Response) {})

I’d be happy to formalise this more and put them here for everyone to use.

26reactions
hakudevcommented, Dec 26, 2020

Install the type definitions for multer.

bash npm install --save @types/multer

Read more comments on GitHub >

github_iconTop Results From Across the Web

uisng multer with typescript: Property 'file' does not exist on ...
js app is written in typescript. I get the following typescript error in my code. Property 'file' does not exist on type 'Request'.ts(2339)....
Read more >
Unable to compile TypeScript. Property 'user' does not exist on ...
Hello, I getting annoyed about typescript in my node api. I have written a jwtverify.ts. At first typescript has not accepted the req.user....
Read more >
How to fix property not existing on EventTarget in TypeScript
This error occurs when you try to access a property on an event target in TypeScript. Property 'value' does not exist on type...
Read more >
TypeScript “Property does not exist on type” | by Mike Diaz
TS2339 : Property does not exist on type ... }, };. Once again, this is simplified, but check out the bolded part, which...
Read more >
TypeScript: JavaScript With Syntax For Types.
TypeScript extends JavaScript by adding types to the language. ... Property 'name' does not exist on type '{ firstName: string; lastName: string; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found