Skip to content

Update part3a.md notes backend post method empty content handling #4081

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

Closed
wants to merge 1 commit into from

Conversation

LCUnger
Copy link

@LCUnger LCUnger commented Jul 1, 2025

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<any, Record<string, any>> | undefined' is not assignable to parameter of type 'Application<Record<string, any>>'.
Type '(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>) => Response<...> | undefined' is missing the following properties from type 'Application<Record<string, any>>': 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.

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<any, Record<string, any>> | undefined' is not assignable to parameter of type 'Application<Record<string, any>>'.
      Type '(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>) => Response<...> | undefined' is missing the following properties from type 'Application<Record<string, any>>': 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.
@vejol vejol added the part 3 label Aug 11, 2025
@vejol
Copy link
Contributor

vejol commented Aug 13, 2025

Thank you for the pull request. This kind of syntax is used several times in different parts of the course material, and I think it is a clear and functional choice for these situations. Therefore, I will not accept this pull request.

@vejol vejol closed this Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants