-
Notifications
You must be signed in to change notification settings - Fork 124
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
Accept Generic Parameters for FormData, Response and Request #11
Comments
Hey! Thanks for your detailed issue, much appreciated. I think I'd prefer not to add generics to Request, Response etc. The main reason is that I want to err towards correctness, not usability. When you call |
Ok, there are 3 points here:
So I think your comment above only relates to point 2. I think the highest value is probably the But maybe this is not the focus of the |
@karlhorky I wonder if you (or even @mattpocock ) with your typing knowledge can help with a tangential question which is out of scope of the In @types/express both the interface Request<
P = core.ParamsDictionary,
ResBody = any,
ReqBody = any,
ReqQuery = core.Query,
Locals extends Record<string, any> = Record<string, any>
> extends core.Request<P, ResBody, ReqBody, ReqQuery, Locals> {} How would you use declaration merging to change these to I have tried variations of the following, which can augment properties but not override; declare global {
namespace Express {
interface Request extends Record<string, unknown> {
addition: "a" | "b"; // Augments ok
body: unknown; // Remains any
}
}
} I understand the risks with overriding the definitions of an external library |
Hey @mattpocock 👋 Hope you're well!
Looks like a cool project! 👀
Wonder if you'd be open for enabling some DX improvements such as enabling
FormData
,Response
andRequest
to take generic type parameters.These have been requested in TypeScript itself, but it seems like the requests won't be implemented:
Motivating Examples
FormData
TypeScript Playground
Response
andRequest
Before:
After:
Caveats
Request
body is unknown until runtime, so this is better handled instead with Zod or some other runtime validation. But for quick/simple projects without this validation, it's nice to be able to type the request body type.The text was updated successfully, but these errors were encountered: