Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's a good point, especially because different return types is well supported in TS.

I made the same in plpgsql recently and opted for returning an implicit union of UserSession | Error, by returning UserSession in the signature and raising errors in the function. The alternative was to return json where you'd have to look at the body of the function to figure out what it returns (when successful), as opposed to the signature.

I'm not sure if I'm striking the right balance. Yes, the signature is "self-documenting" - until you hit an error!



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: