[HN Gopher] Automatically generating types for Cloudflare Workers
       ___________________________________________________________________
        
       Automatically generating types for Cloudflare Workers
        
       Author : tekkertje
       Score  : 30 points
       Date   : 2021-11-16 20:43 UTC (2 hours ago)
        
 (HTM) web link (blog.cloudflare.com)
 (TXT) w3m dump (blog.cloudflare.com)
        
       | lukekim wrote:
       | You can also do this manually with quicktype.io. We've found it
       | useful from the number of languages it supports.
        
       | eminence32 wrote:
       | This is nice. I started to learn Cloudflare Workers a few months
       | ago, and used TypeScript for my project. Since I was to this
       | platform, I relied heavily on the TS types and tab completion in
       | my IDE to explore the APIs and to make sure I was using them
       | correctly. Unfortunately there were several gaps which lead to a
       | less-than-ideal development experience and general confusion.
        
         | kmf wrote:
         | The story around types in Workers should be leaps-and-bounds
         | better than it was a few months ago (thanks to the work
         | outlined in this blog post) - would love to hear your thoughts
         | on this new work, and hope it helps!
        
       | brundolf wrote:
       | Generated types are much better than manually-updated types when
       | you've got a source of truth that lives in a different codebase,
       | but I can't help feel like we could do better. I wish there were
       | a "lingua franca" for type declarations that could be understood
       | directly by different languages. Not only would you avoid the
       | mess that is generated source code, but it could be a n^2 -> 2n
       | situation, like LLVM and LSP, where you only have to translate to
       | and from this common ground instead of to and from every
       | combination of leaves.
       | 
       | Unfortunately it might be pretty challenging given how different
       | type systems can be. But maybe if you started with a subset of
       | popular languages that have similar-enough type concepts?
        
         | ZitchDog wrote:
         | I think protocol buffers is pretty similar to what you're
         | looking for.
        
           | brundolf wrote:
           | Maybe. Those seem pretty low-level though; I'm thinking of
           | something abstract enough to be used with TypeScript or
           | GraphQL just as easily as Rust or Kotlin. So byte-layouts are
           | likely too specific.
           | 
           | (Correct me if I'm wrong about how Protocol Buffers work)
           | 
           | I think Serde is the closest thing I've seen to what I'm
           | getting at; the way it can freely translate between XML and
           | JSON and Rust structures without any help. But of course it's
           | not a standalone schema language.
        
       ___________________________________________________________________
       (page generated 2021-11-16 23:01 UTC)