Re:A generically typed pipe function in TypeScript
by jackblemming on Sunday August 07, 2022 @02:42PM
(#32378668)
Why does it matter how complicated it is if you’re not the one maintaining it? Your head would probably spin if you saw how complicated the database code you use is, as a backend dev.
[ Parent
| on HN ]
Re:A generically typed pipe function in TypeScript
by semicolon_storm on Sunday August 07, 2022 @03:01PM
(#32378846)
Some domains require horribly complicated code that I’m perfectly happy admitting that I’ll never understand it. Chaining function calls is not one of those domains.
I suppose I don’t really care, it’s not my library and I’ll never use it, it’s just interesting to see how differently styled it is.
Re:A generically typed pipe function in TypeScript
by cobertos on Monday August 08, 2022 @12:46AM
(#32382452)
Chaining functions _does_ need this though, in current Typescript. The pipe function has to enforce some really complex constraints (inner types between siblings/fn args). There's really no other "correct" way to write this without calling it a day and just doing a generic for different amount of args (<A>, <A, B>, <A, B, C>, etc).
I agree it's complex, but necessary for a utility like this if you want correctness for arbitrary N args