r/typescript

Typescript: how do I make a generic function to validate incoming POST requests if each request will have a different body?

I want to make a generic validateRequest() function for my web server that will take in any incoming request and check some things to make sure everything is good. The problem is that each request could have a potentially different body. The way I have it set up right now is that it works to validate 1 type of request, but that's because I passed in the exact model of the request in the function's parms.

validateRequest(req: Request<object, object, RequestModel1>, someOtherParm: number): [number, string] {}

Each of the different possible bodys of a valid request will share one field - I need to be able to validate the value in this field, regardless of the shape of the body of the incoming request. I also am very security-conscious, so I want to make sure whatever solution I end up with here won't put me at risk of accepting an incoming request that is bogus or malicious. How would I modify my function to handle this?

reddit.com
u/Reasonable-Job4205 — 11 days ago

Anyone else still writing most of their TypeScript by hand

Agents are great for a lot of things, but I still write most of my TypeScript by hand, and on a team where nobody else does, my PRs are now the slow ones. Mine take a day, theirs take 20 minutes and go through the same coderabbit / claude review pass as mine.

Is anyone else still working like this, or am I just slow now?

reddit.com
u/Specialist_Agent3599 — 14 days ago

Joist 2.4 with new SQL Builder, Lazy Fields, more...

Hello r/typescript ! We just released Joist 2.4, which has a new low-level query builder API:

https://joist-orm.io/blog/joist-2-4/

Because Joist is an entity-based ORM, we've always had very robust "load entity" query APIs, but historically considered "creating adhoc SQL queries" as not our strong suit / nothing we had particularly innovative ideas about, so expected users to use a knex-type library alongside Joist.

Now in Joist 2.4, we've built out a low-level em.query API, with a ~somewhat novel "just POJOs / not fluent" API that fits in with Joist's overall DX, and means codebases don't need the "dual Joist/Knex" setup anymore.

Happy to have folks check it out; disclaimer since its a new feature, I'm sure we're missing things & will keep iterating based on feedback. Thanks!

reddit.com
u/shaberman — 14 days ago