{"id":28741223,"url":"https://github.com/coder/guts","last_synced_at":"2026-01-21T21:12:46.539Z","repository":{"id":264901907,"uuid":"894619353","full_name":"coder/guts","owner":"coder","description":"Guts is a code generator that converts Golang types to Typescript. Useful for keeping types in sync between the front and backend.","archived":false,"fork":false,"pushed_at":"2026-01-12T22:26:33.000Z","size":2276,"stargazers_count":292,"open_issues_count":5,"forks_count":11,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-15T07:10:52.063Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-11-26T17:14:53.000Z","updated_at":"2026-01-06T18:18:24.000Z","dependencies_parsed_at":"2025-07-28T20:14:47.798Z","dependency_job_id":"2374370a-49a6-4889-a16a-d220bf99d271","html_url":"https://github.com/coder/guts","commit_stats":null,"previous_names":["coder/gots","coder/guts"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/coder/guts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coder%2Fguts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coder%2Fguts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coder%2Fguts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coder%2Fguts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coder","download_url":"https://codeload.github.com/coder/guts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coder%2Fguts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28643114,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T18:04:35.752Z","status":"ssl_error","status_checked_at":"2026-01-21T18:03:55.054Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-16T07:11:26.878Z","updated_at":"2026-01-21T21:12:46.529Z","avatar_url":"https://github.com/coder.png","language":"Go","readme":"# Go Unto Ts (guts)\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/coder/guts.svg)](https://pkg.go.dev/github.com/coder/guts)\n\n`guts` is a tool to convert golang types to typescript for enabling a consistent type definition across the frontend and backend. It is intended to be called and customized as a library, rather than as a command line executable.\n\nSee the [simple example](./example/simple) for a basic usage of the library.\n```go\ntype SimpleType[T comparable] struct {\n\tFieldString     string\n\tFieldInt        int\n\tFieldComparable T\n\tFieldTime       time.Time\n}\n```\n\nGets converted into\n\n```typescript\ntype Comparable = string | number | boolean;\n\n// From main/main.go\ninterface SimpleType\u003cT extends Comparable\u003e {\n    FieldString: string;\n    FieldInt: number;\n    FieldComparable: T;\n    FieldTime: string;\n}\n```\n\n# How to use it\n\n`guts` is a library, not a command line utility. This is to allow configuration with code, and also helps with package resolution.\n\nSee the [simple example](./example/simple) for a basic usage of the library. A larger example can be found in the [Coder repository](https://github.com/coder/coder/blob/main/scripts/apitypings/main.go).\n\n```go\n// Step 1: Create a new Golang parser\ngolang, _ := guts.NewGolangParser()\n\n// Optional: Preserve comments from the golang source code\n// This feature is still experimental and may not work in all cases\ngolang.PreserveComments()\n\n// Step 2: Configure the parser\n_ = golang.IncludeGenerate(\"github.com/coder/guts/example/simple\")\n// Step 3: Convert the Golang to the typescript AST\nts, _ := golang.ToTypescript()\n// Step 4: Mutate the typescript AST\nts.ApplyMutations(\n    config.ExportTypes, // add 'export' to all top level declarations\n)\n// Step 5: Serialize the typescript AST to a string\noutput, _ := ts.Serialize()\nfmt.Println(output)\n```\n\n\n# How it works\n\n`guts` first parses a set of golang packages. The Go AST is traversed to find all the types defined in the packages. \n\nThese types are placed into a simple AST that directly maps to the typescript AST.\n\nUsing [goja](https://github.com/dop251/goja), these types are then serialized to typescript using the typescript compiler API. \n\n\n# Generator Opinions\n\nThe generator aims to do the bare minimum type conversion. An example of a common opinion, is to use types to represent enums. Without the mutation, the following is generated:\n\n```typescript\nexport enum EnumString {\n    EnumBar = \"bar\",\n    EnumBaz = \"baz\",\n    EnumFoo = \"foo\",\n    EnumQux = \"qux\"\n}\n```\n\nAdd the mutation:\n```golang\nts.ApplyMutations(\n\tconfig.EnumAsTypes,\n)\noutput, _ := ts.Serialize()\n```\n\nAnd the output is:\n\n```typescript\nexport type EnumString = \"bar\" | \"baz\" | \"foo\" | \"qux\";\n```\n\n# Alternative solutions\n\nThe guts package was created to offer a more flexible, programmatic alternative to existing Go-to-TypeScript code generation tools out there.\n\nThe other solutions out there function as command-line utilities with yaml configurability. `guts` is a library, giving it a much more flexible and dynamic configuration that static generators can’t easily support.\n\nUnlike many of its counterparts, guts leverages the official TypeScript compiler under the hood, ensuring that the generated TypeScript definitions are semantically correct, syntactically valid, and aligned with the latest language features.\n\n\n# Helpful notes\n\nAn incredible website to visualize the AST of typescript: https://ts-ast-viewer.com/\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoder%2Fguts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoder%2Fguts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoder%2Fguts/lists"}