Staging Ground Beta Test Signup

Signup for the Staging Ground Beta Test
Dec 6, 2022 17:07
@YaakovEllis - I would like to volunteer.
 
Aug 28, 2022 19:11
You could post this as a seperate question. Maybe someone else knows the correct type for this function
Aug 28, 2022 19:11
We are using it succesfully but that is not the issue with the function. Express does not seem to expose a type for the function. Using Request and Response does not work well with the merging. So we need to let TypeScript infer the types by passing it to app.use
Aug 28, 2022 19:09
what merging
Aug 28, 2022 19:07
You could also pass the app object to another file to use it is there
Aug 28, 2022 19:03
The function needs to be passed to app.use directly. I sadly did not find a type for the function that can be used here. Passing it directly to app.use will let TypeScript infer the types
Aug 28, 2022 18:56
Yes, or otherwise make app available in the middleware file.
Aug 28, 2022 18:51
If you dont give an explicit type and hover over res and req you can see these types
Aug 28, 2022 18:48
If you put the type Request on the res parameter, it is technically the wrong type as the correct type would be Request<ParamsDictionary, any, any, QueryString.ParsedQs, Record<string, any>> but this is too annoying to write out.
Aug 28, 2022 18:45
I added some comments in the code for important details
Aug 28, 2022 18:44
We need to let TypeScript infer most of the types. The types of express are often too verbose to write them out manually
Aug 28, 2022 18:44
@Ayan - I reproduced your project locally. See the update to the answer.
Aug 28, 2022 18:10
@Ayan - Does the error change if you move the declare namespace in the same file as the middleware?
Aug 28, 2022 13:33
@Ayan - That does not look like a runtime error. That error is definitely produced by TypeScript during compile time. How are you compiling the app? Just tsc or something with webpack?
Aug 28, 2022 13:33
@Ayan - On which line does this error happen?
Aug 28, 2022 13:33
@Ayan - I just checked what type res.status(status).json returns as this is also the return type of your function if you just return its result.
Aug 28, 2022 13:33
@Ayan - Yes, you specified that success and error are optional, so a Response might or might not have them. You would either need to check if they are defined before calling them, or remove the question mark.
Aug 28, 2022 13:33
@Ayan - You need in the declare namespace Express { ... for the type of the argument in the function but also in the responseHelper because you are using it as the type of the argument of res.success too.
Aug 28, 2022 13:33
@Ayan - Well you are gonna need this interface in both files. So you may export it and import it in the other file.