From 336745064e0d85330681323d6683cba50419f102 Mon Sep 17 00:00:00 2001 From: LCUnger <161487689+LCUnger@users.noreply.github.com> Date: Tue, 1 Jul 2025 13:15:12 +0200 Subject: [PATCH] Update part3a.md notes backend post method empty content handling I've been following along the course in typescript, note that I'm really not experienced with it. But I did a course on it just before this one and wanted to get some experience with it. This part of the code wouldn't work (line 672 gave an ts error, see error below). All ai tools I tried also didn't understand it. I think it's because the Type 'Response' which you would give the response variable if you're working in typescript doesn't allow for returning it or the post function type doesn't like it. By forcing any on the req and res I got it working but this felt of because everyone tells me you shouldn't use any in ts. From just intuition it felt weird returning a response method. So I tried separating the return to after editing the response status. This fixed everything. I know this part of the course is not made for typescript, but I figured if typescript likes it, it's may be a better way to write the code. Error: src/index.ts:62:24 - error TS2769: No overload matches this call. The last overload gave the following error. Argument of type '(req: Request, res: Response) => express.Response> | undefined' is not assignable to parameter of type 'Application>'. Type '(req: Request>, res: Response>) => Response<...> | undefined' is missing the following properties from type 'Application>': init, defaultConfiguration, engine, set, and 63 more. 62 app.post('/api/notes', (req: Request, res: Response) => { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ node_modules/@types/express-serve-static-core/index.d.ts:168:5 168 (path: PathParams, subApplication: Application): T; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The last overload is declared here. --- src/content/3/en/part3a.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/content/3/en/part3a.md b/src/content/3/en/part3a.md index 7dedc11a8c1..0797fbc739e 100644 --- a/src/content/3/en/part3a.md +++ b/src/content/3/en/part3a.md @@ -670,9 +670,10 @@ app.post('/api/notes', (request, response) => { const body = request.body if (!body.content) { - return response.status(400).json({ + response.status(400).json({ error: 'content missing' }) + return; } const note = {