{"repo":"gzuidhof/tygo","free":true,"listed":false,"github":"https://github.com/gzuidhof/tygo","clone":"git clone https://github.com/gzuidhof/tygo.git","description":"Generate Typescript types from Golang source code","language":"Go","stars":909,"topics":["codegen","golang","types","typescript"],"license":"MIT","category":"dev-tools","readme_excerpt":"🎑 tygo Tygo is a tool for generating Typescript typings from Golang source files that just works. It preserves comments, understands constants and also supports non-struct type expressions. It's perfect for generating equivalent types for a Golang REST API to be used in your front-end codebase. 🚀 Supports Golang 1.18 generic types and struct inheritance Installation Example Golang input file Typescript output (with default enum style: \"const\" ) For a real baptism by fire example, here is a Gist with output for the Go built-in net/http and time package. Usage Option A: CLI (recommended) Create a file tygo.yaml in which you specify which packages are to be converted and any special type mappings you want to add. Then run The output Typescript file will be next to the Go source files. Option B: Library-mode Config See also the source file tygo/config.go. Type hints through tagging You can tag struct fields with tstype to specify their output Typescript type. Custom type mapping Alternative You could use the frontmatter field in the config to inject export type Genre = \"novel\" \"crime\" \"fantasy\" at the top of the file, and use tstype:\"Genre\" . I personally prefer that as we may use the Genre type more than once. tygo:emit directive Another way to generate types that cannot be directly represented in Go is to use a //tygo:emit directive to directly emit literal TS code. The directive can be used in two ways. A tygo:emit directive on a struct will emit the remainder of the directi","default_branch":null,"files":null,"tree":[],"storefront":"/r/gzuidhof","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/gzuidhof/tygo/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}