{"id":13606586,"url":"https://github.com/dtgorski/typex","last_synced_at":"2026-01-16T05:36:14.723Z","repository":{"id":54978068,"uuid":"249817344","full_name":"dtgorski/typex","owner":"dtgorski","description":"[TOOL/CLI] - Filter and examine Go type structures, interfaces and their transitive dependencies and relationships. Export structural types as TypeScript value object or bare type representations.","archived":false,"fork":false,"pushed_at":"2023-09-15T22:02:29.000Z","size":68,"stargazers_count":205,"open_issues_count":0,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T08:40:28.968Z","etag":null,"topics":["cli","export","go","golang","struct","tree","type","typescript"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dtgorski.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2020-03-24T21:02:44.000Z","updated_at":"2025-02-07T12:36:37.000Z","dependencies_parsed_at":"2024-01-08T16:09:20.146Z","dependency_job_id":"0abf52ee-35fc-454f-b874-0ddd7e27f62e","html_url":"https://github.com/dtgorski/typex","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/dtgorski/typex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtgorski%2Ftypex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtgorski%2Ftypex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtgorski%2Ftypex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtgorski%2Ftypex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dtgorski","download_url":"https://codeload.github.com/dtgorski/typex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtgorski%2Ftypex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28477363,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T03:13:13.607Z","status":"ssl_error","status_checked_at":"2026-01-16T03:11:47.863Z","response_time":107,"last_error":"SSL_read: 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":["cli","export","go","golang","struct","tree","type","typescript"],"created_at":"2024-08-01T19:01:10.456Z","updated_at":"2026-01-16T05:36:14.702Z","avatar_url":"https://github.com/dtgorski.png","language":"Go","funding_links":[],"categories":["Go Tools","Go 工具","Go","Libraries for creating HTTP middlewares"],"sub_categories":["Routers","路由器","Search and Analytic Databases","代码分析"],"readme":"[![Open Issues](https://img.shields.io/github/issues/dtgorski/typex.svg)](https://github.com/dtgorski/typex/issues)\n[![Report Card](https://goreportcard.com/badge/github.com/dtgorski/typex)](https://goreportcard.com/report/github.com/dtgorski/typex)\n[![Awesome Go](https://awesome.re/badge.svg)](https://github.com/avelino/awesome-go#user-content-go-tools)\n\n## typex\n\nExamine [Go](https://golang.org/) types and their transitive dependencies. Export results as TypeScript value objects (or types) declaration.\n\n### Installation\n```\ngo install github.com/dtgorski/typex@latest\n```\n\n### Synopsis\nThe CLI command ```typex``` filters and displays [Go](https://golang.org/) type structures, interfaces and their relationships across package boundaries.\nIt generates a type hierarchy tree with additional references to transitive dependencies vital for the filtered types.\nAs an additional feature, ```typex``` exports the result tree as a [TypeScript](https://www.typescriptlang.org/) projection representing value objects or bare types.\n\n### Examples\n**Go type hierarchy layout**\n  ```\n  $ typex -f=Rune io/...\n\n  ├── error interface {\n  │       Error() string\n  │   }\n  └── io\n      ├── RuneReader interface {\n      │       ReadRune() (r rune, size int, err error)\n      │   }\n      └── RuneScanner interface {\n              io.RuneReader\n              ReadRune() (r rune, size int, err error)\n              UnreadRune() error\n          }\n  ```\n  ```\n  $ typex -f=Render github.com/dtgorski/typex/...\n\n  └── github.com\n      └── dtgorski\n          └── typex\n              └── internal\n                  ├── PathReplaceFunc func(string) string\n                  ├── go\n                  │   └── TypeRender struct {\n                  │           PathReplaceFunc internal.PathReplaceFunc\n                  │           IncludeUnexported bool\n                  │       }\n                  └── ts\n                      └── TypeRender struct {\n                              PathReplaceFunc internal.PathReplaceFunc\n                              IncludeUnexported bool\n                          }\n  ```\n\n**TypeScript value object layout**\n  ```\n  $ typex -f=File -l=ts-class mime/multipart\n\n  export module mime {\n      export module multipart {\n          export class FileHeader {\n              constructor(\n                  readonly Filename: string,\n                  readonly Header: net.textproto.MIMEHeader,\n                  readonly Size: number,\n              ) {}\n          }\n      }\n  }\n  export module net {\n      export module textproto {\n          export type MIMEHeader = Record\u003cstring, string[]\u003e\n      }\n  }\n  ```\n\n**TypeScript bare type layout**\n  ```\n  $ typex -f=File -l=ts-type mime/multipart\n\n  export module mime {\n      export module multipart {\n          export type FileHeader = {\n              Filename: string,\n              Header: net.textproto.MIMEHeader,\n              Size: number,\n          }\n      }\n  }\n  export module net {\n      export module textproto {\n          export type MIMEHeader = Record\u003cstring, string[]\u003e\n      }\n  }\n  ```\n\n### TypeScript and reserved keywords\nBasically, the names of types and fields will be exported from Go without modification.\nCollisions with reserved keywords or standard type names in the target language may occur.\nTo avoid conflicts, you may use the JSON tag annotation for the exported fields of a struct as described in the [json.Marshal(...)](https://golang.org/pkg/encoding/json/#Marshal) documentation.\n\n### TypeScript and exportable types\nDue to fundamental language differences, ```typex``` is not capable of exporting all type declarations one-to-one. Refer to the type mapping table below. \nGo channel, interface and function declarations will be omitted, references to these declarations will be typed with ```any```.\n\n### TypeScript type mapping\nTypeScript (resp. JavaScript aka ECMAScript) lacks a native integer number type.\nThe numeric type provided there is inherently a 64 bit float.\nYou should keep this in mind when working with exported numeric types - this includes `byte` and `rune` type aliases as well.    \n\n|Go native type|TypeScript type\n| --- | ---\n|```bool```|```boolean```\n|```string```|```string```\n|```map```|```Record\u003cK, V\u003e```\n|```struct``` ```(named)```|```T```\n|```struct``` ```(anonymous)```|```{}```\n|```array``` ```(slice)```|```T[]```\n|```complex```[```64```\u0026vert;```128```]|```any```\n|```chan```, ```func```, ```interface```|```any```\n|```int```[```8```\u0026vert;```16```\u0026vert;```32```\u0026vert;```64```]|```number```\n|```uint```[```8```\u0026vert;```16```\u0026vert;```32```\u0026vert;```64```]|```number```\n|```byte```(=```uint8```)|```number```\n|```rune```(=```int32```)|```number```\n|```float```[```32```\u0026vert;```64```]|```number```\n|```uintptr```|```number```\n\n### Usage\n\n```\n$ typex -h\n```\n```\nUsage: typex [options] package...\nExamine Go types and their transitive dependencies. Export\nresults as TypeScript value objects (or types) declaration.\n\nOptions:\n    -f \u003cname\u003e\n        Type name filter expression. Repeating the -f option\n        is allowed, all expressions aggregate to an OR query.\n\n        The \u003cname\u003e filter can be a type name, a path part or\n        a regular expression. Especially in the latter case,\n        \u003cname\u003e should be quoted or escaped correctly to avoid\n        errors during shell interpolation. Filters are case\n        sensitive, see examples below.\n\n        The result tree will contain additional references to\n        transitive dependencies vital for the filtered types.\n\n    -l \u003clayout\u003e\n        Modify the export layout. Available layouts are:\n          * \"go\":       the default Go type dependency tree\n          * \"ts-type\":  TypeScript type declaration projection\n          * \"ts-class\": TypeScript value object projection\n\n    -r \u003cold-path\u003e:\u003cnew-path\u003e\n        Replace matching portions of \u003cold-path\u003e in a fully\n        qualified type name with \u003cnew-path\u003e string. Repeating\n        the -r option is allowed, substitutions will perform\n        successively. \u003cold-path\u003e can be a regular expression.\n        \n        The path replacement/relocation can be used to modify\n        locations of type hierarchies, e.g. prune off the\n        \"github.com\" reference from qualified type name path\n        by omitting the \u003cnew-path\u003e part after the colon. \n\n    -t  Go tests (files suffixed _test.go) will be included\n        in the result tree available for a filter expression\n\n    -u  Unexported types (lowercase names) will be included\n        in the result tree available for a filter expression.\n\n    -x \u003cname\u003e \n        Exclude type names from export. Repeating this option\n        is allowed, all expressions aggregate to an OR query.\n        The exclusion filter can be a type name, a path part\n        or a regular expression.\n\nMore options:\n    -h  Display this usage help and exit.\n    -v  Print program version and exit.\n\nThe 'package' argument denotes one or more package import path\npatterns to be inspected. Patterns must be separated by space.\nA pattern containing '...' specifies the active modules whose\nmodules paths match the pattern.\n\nExamples:\n    $ typex -u go/...\n    $ typex -u -f=URL net/url\n    $ typex github.com/your/repository/...\n    $ typex -l=ts-type github.com/your/repository/...\n    $ typex -r=github.com:a/b/c github.com/your/repository/...\n\nThis tool relies heavily on Go's package managing subsystem and\nis bound to its features and environmental execution context.\n```\n\n### Known issues\n* Occasional(?) ```internal error``` from Go's package managing subsystem [has been reported](https://github.com/dtgorski/typex/issues/4) on Go 1.14.6 darwin/amd64. Newer Go versions \u003e= 1.15 seem to be not affected.\n\n### Disclaimer\nThe implementation and features of ```typex``` follow the [YAGNI](https://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it) principle.\nThere is no claim for completeness or reliability.\n\n### @dev\nTry ```make```:\n```\n$ make\n\n make help       Displays this list\n make clean      Removes build/test artifacts\n make build      Builds a static binary to ./bin/typex\n make debug      Starts debugger [:2345] with ./bin/typex\n make install    Compiles and installs typex in Go environment\n make test       Runs tests, reports coverage\n make tidy       Formats source files, cleans go.mod\n make sniff      Checks format and runs linter (void on success)\n```\n\n### License\n[MIT](https://opensource.org/licenses/MIT) - © dtg [at] lengo [dot] org\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtgorski%2Ftypex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdtgorski%2Ftypex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtgorski%2Ftypex/lists"}