News for hackers. Stuff that matters.
Re:TypeScript is terrible for library developers by franciscop on Tuesday August 23, 2022 @04:42PM (#32571194)
That's an order of magnitude less clear in what the function expects than the examples I gave IMHO
Re:TypeScript is terrible for library developers by spankalee on Tuesday August 23, 2022 @07:34PM (#32573038)
Actually, it's not. With the type signature I understand what arguments the function can take. With your examples I have to _infer_ that, and there could be other restrictions that I wouldn't know. Like, can you pass a function and a string? Or do all the arguments have to be functions or not? The type signature tells me right away.
Re:TypeScript is terrible for library developers by franciscop on Wednesday August 24, 2022 @12:30AM (#32575001)
How are literal examples that are strings less clear than saying "string"? How do you know with just "string" the separator method, the format, etc? In my example you have type information AND string format information AND examples, while with TS you'd only have type information
Re:TypeScript is terrible for library developers by phailhaus on Wednesday August 24, 2022 @10:42AM (#32580100)
Again, TS does not forbid you from having examples. Your docstrings don't replace Typescript, and Typescript doesn't replace good docstrings. But your docstrings are very unclear on which types you can mix together, and that has to be inferred. And if a user passes in something else by accident, it will fail at runtime rather than warning them the moment they write it.
Re:TypeScript is terrible for library developers by phailhaus on Tuesday August 23, 2022 @04:58PM (#32571419)
Who's stopping you from giving examples in a docstring?
Re:TypeScript is terrible for library developers by spiralx on Wednesday August 24, 2022 @12:45AM (#32575096)
You can use recursion and template types to type some pretty complex string values now - I've seen cut down parsers for both SQL and TS written just via TS types which is madness but does show what can be done.

Whether the effort is worth it is, however, a totally different question to whether it's possible.