3 ms·
One clear moral of this story is that, as a library developer, I need a lot more documentation and tooling support from the TypeScript team. That string-parsin
by dfabulich 4y ago
One clear moral of this story is that, as a library developer, I need a lot more documentation and tooling support from the TypeScript team.
That string-parsing thing isn't in TypeScript's documentation at all; it's a random blog post. I'm lucky I found it. TypeScript's site should document how to do this.
Furthermore, it should be easier to debug parsed stringly-typed APIs using the `infer` keyword. Today, I just run the compiler over and over again until it stops throwing errors, and the errors are really not very helpful.
There should be a standard tool to help me test that I used `infer` correctly, ideally helping me by fuzzing the code to see if I allowed something I shouldn't have allowed, or blocked something that I should have allowed, and to test against various versions of TypeScript.
Narrowing types shouldn't be done just by nesting ternary expressions. As the article notes, "It's pretty common in style guides to never nest ternaries. In typescript, that's the only way to narrow types based on other types. It's a mess!"
Lastly, this idea doesn't sit right with me:
> I would say that the increased complexity of your project would accurately reflect the complexity of the underlying API
I designed my library so it doesn't need to incorporate that complexity. Users of my API have to learn the API, but they can learn it from Apple, by reading Apple's documentation, and by inspecting the objects that Apple actually returns (rather than what their OpenAPI specification says they'll return).
Incorporating that complexity into my library will make my library harder to work with, more difficult for others to contribute to my library. As the article says, "Types make it much harder to maintain a js library, and especially difficult to contribute to them."
TypeScript is forcing me to duplicate the API's complexity in my code. Even if you think that "sounds worth the work," I think you have to agree that the work load is much higher than the work I've already done.
- CRConrad 4y ago> Furthermore, it should be easier to debug parsed stringly-typed APIs using the `infer` keyword. Today, I just run the compiler over and over again until it stops throwing errors, and the errors are really not very helpful. This paragraph kind of sums up both the OP and this whole HN discussion of it. So I'll throw my comment on here, although I suppose it could go pretty much anywhere. Anyway, one way to read it all is: This just goes to show that 1) JavaScript sucks; 2) Therefore the whole world of "Web apps" built on it is an unmaintainable buggy nightmare; 3) Trying to graft "strong" (not really) typing on top of it in the shape of TypeScript is just polishing a turd. It's like somewhere around 1995/2000 the world of computing jumped through a time warp back to 1975, and we've been stuck there, in a world dominated by the new BASIC, ever since. ___ Edit: Typo fix, *"domination" --> "dominated".