Typescript: Property 'file' does not exist on type 'Request'
See original GitHub issueBecause 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:
- Created 7 years ago
- Reactions:12
- Comments:12 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I haven’t been writing them, but I could. I just have a simple local definition for myself that looks like this:
I’d be happy to formalise this more and put them here for everyone to use.
Install the type definitions for multer.
bash npm install --save @types/multer