New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Documentation] Express Typing #12
Comments
To solve the problem:
I think we can close this issue. |
@thomrick He's asking that the examples on https://kamilmysliwiec.gitbooks.io/nest/content/ add the Express types. Right now they just say:
as opposed to
|
unfortunately not possible to import import { Response, Request } from '@types/express';
import {
Response as Req,
Request as Res
} from 'nest.js'; |
When trying to do the above I get:
Here is the code I'm trying to transpile
This was addressed by #36 |
Since latest version |
I found an issue with decorators being used on function parameters that might be related to this. when using something like @Get('playlist')
async getPlaylist(@Res() res) {
res.send(playlist);
} This will only work so long as your typescript's tsconfig.json is targeting es2015 or higher, if targeting es5, this will throw an error like so: [Nest] 17957 - 2017-8-2 22:14:37 [ExceptionsHandler] res.send is not a function
TypeError: res.send is not a function
at PlaylistController.<anonymous> (/Users/mark.mccracken/Work/learning/angular/state-management/dist/server/playlist/playlist.controller.js:118:43)
at step (/Users/mark.mccracken/Work/learning/angular/state-management/dist/server/playlist/playlist.controller.js:44:23)
at Object.next (/Users/mark.mccracken/Work/learning/angular/state-management/dist/server/playlist/playlist.controller.js:25:53)
at /Users/mark.mccracken/Work/learning/angular/state-management/dist/server/playlist/playlist.controller.js:19:71
at Promise (<anonymous>)
at __awaiter (/Users/mark.mccracken/Work/learning/angular/state-management/dist/server/playlist/playlist.controller.js:15:12)
at PlaylistController.getPlaylist (/Users/mark.mccracken/Work/learning/angular/state-management/dist/server/playlist/playlist.controller.js:116:16)
at /Users/mark.mccracken/Work/learning/angular/state-management/node_modules/@nestjs/core/router/router-proxy.js:7:33
at Layer.handle [as handle_request] (/Users/mark.mccracken/Work/learning/angular/state-management/node_modules/@nestjs/core/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/mark.mccracken/Work/learning/angular/state-management/node_modules/@nestjs/core/node_modules/express/lib/router/route.js:131:13)
::1 - - [02/Aug/2017:21:14:37 +0000] "GET /api/playlist HTTP/1.1" 500 31 Hope this might help anyone coming behind me with a really simple solution |
This is happening to me also with ES6 in tsconfig.json. |
When it was said that this framework works in TypeScript I expected it to support express types integrally. For example - I don't need to import the express module because NestJS does that for me. Why than would I need to import express types? The types should be imported and inferred automatically when I use the @Req decorator. |
@ShacharHarshuv that's not how decorators work in TS. |
What if I'll just need to write the type (e.g. Request) without a decorator and Nest will give me the request like happens with dependency injection? (You ask for a class and the injector supplies you with an instant.) |
Then the server package would still need to have both Fastify and Nest platform installed for it to work, and Nest still supports JS, so that's not an option either, plus it's more a downgrade than an actual bug fix imo. |
Any update on this? I still face the same issue when targeting es2017. Using Nest 6.5.3 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
It's really good to see a web framework that deals with TypeScript as a first class citizen! I'm really excited about this project because of this.
However, when turning the option:
noImplicitAny
in thetsconfig.json
the compiler will produce warnings about a lot of the examples in the documentation.I highly recommend adding Express TypeScript declarations to the examples like so:
The text was updated successfully, but these errors were encountered: