{"id":22796371,"url":"https://github.com/lil5/typex2","last_synced_at":"2025-04-19T13:08:44.182Z","repository":{"id":56539917,"uuid":"307290135","full_name":"lil5/typex2","owner":"lil5","description":"Reads a go package's types and export them to typescript interfaces and basic types.","archived":false,"fork":false,"pushed_at":"2024-11-07T12:07:59.000Z","size":42,"stargazers_count":2,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-07T12:35:25.936Z","etag":null,"topics":["cli","export","generate","generator","go","golang","struct","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/lil5.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}},"created_at":"2020-10-26T07:18:32.000Z","updated_at":"2024-11-07T12:06:08.000Z","dependencies_parsed_at":"2022-08-15T20:31:49.901Z","dependency_job_id":null,"html_url":"https://github.com/lil5/typex2","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lil5%2Ftypex2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lil5%2Ftypex2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lil5%2Ftypex2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lil5%2Ftypex2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lil5","download_url":"https://codeload.github.com/lil5/typex2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229333154,"owners_count":18056671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","generate","generator","go","golang","struct","type","typescript"],"created_at":"2024-12-12T05:12:37.410Z","updated_at":"2025-04-19T13:08:44.164Z","avatar_url":"https://github.com/lil5.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Go](https://github.com/lil5/typex2/actions/workflows/go.yml/badge.svg)](https://github.com/lil5/typex2/actions/workflows/go.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/lil5/typex2)](https://goreportcard.com/report/github.com/lil5/typex2)\n\n# TypeX 2\n\nReads a go package's types and export them to TypeScript interfaces and basic types.\n\n🆕 Now with support for Dart, Kotlin and Swift!\n\nGreat for keeping frontend types the same as your go backend.\n\nThis is the follow up of https://github.com/dtgorski/typex\n\n## Installation\n\n```\ngo install github.com/lil5/typex2@1.3.0\n```\n\n## Usage\n\n```\n$ typex2 -l typescript -i ./examples -o ./examples/typex2.ts\n```\n\nThis will do the following;\n\n1. Read all go files inside the path specified (must use one [package name](https://blog.golang.org/package-names)).\n2. Generate typescript [types](https://www.typescriptlang.org/docs/handbook/basic-types.html) and [interfaces](https://www.typescriptlang.org/docs/handbook/interfaces.html) from said go files.\n3. Write generated content into `./examples/typex2.ts`.\n\n## Help\n\n```\n$ typex2 -h\nNAME:\n   typex2 - Convert go structs to other language types\n\nUSAGE:\n   typex2 [global options] command [command options] path\n\nDESCRIPTION:\n   Useful for generating types from golang json RestAPI projects for a frontend to ingest.\n\n   Example:\n   typex2 -l kotlin -i . -o ./classes.kotlin\n\nCOMMANDS:\n   help, h  Shows a list of commands or help for one command\n\nGLOBAL OPTIONS:\n   --lang value, -l value, --language value  Language to generate to [typescript, dart, kotlin, swift] (default: typescript)\n   --input value, -i value                   Input directory to read go types from (default: \".\")\n   --output value, -o value                  Output path \u0026 file to write translated types to\n   --help, -h                                show help\n```\n\n## Language type mapping\n\n\u003e copy from Typex readme\n\u003e\n\u003e https://github.com/dtgorski/typex#typescript-type-mapping\n\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 types|TypeScript|Dart 🆕|Kotlin 🆕|Swift 🆕|Rust 🆕|\n| --- | --- | --- | --- | --- | --- |\n|`bool`|`boolean`|`bool`|`Boolean`|`Bool`|`bool`|\n|`string`|`string`|`String`|`String`|`String`|`String`|\n|`map`|`Record\u003cK, V\u003e`|`Map\u003cK, V\u003e`|`Map\u003cK, V\u003e`|`Dictionary\u003cK, V\u003e`|`Map\u003cK, V\u003e`|\n|`interface`|`Record\u003cstring, any\u003e`|`Map\u003cString, dynamic\u003e`|`Map\u003cString, Any\u003e`|`Dictionary\u003cString, Any\u003e`|`Map\u003cK, V\u003e`|\n|`struct` `(named)`|`T`|`dynamic`|`Any`|`Any`|`\u003cT1\u003e`|\n|`struct` `(anonymous)`|`{}`|`dynamic`|`Any`|`Any`|`\u003cT2\u003e`|\n|`array` `(slice)`|`T[]`|`List\u003cT\u003e`|`Array\u003cT\u003e`|`Array\u003cT\u003e`|`Vec\u003cT\u003e`|\n|`complex`[`64`\u0026vert;`128`]|`any`|`dynamic`|`Float`|`Float`|`f64`|\n|`chan`, `func`, `interface`|`any`|`dynamic`|`Any`|`Any`|`T3`|\n|`int`[`8`\u0026vert;`16`\u0026vert;`32`\u0026vert;`64`]|`number`|`int`|`Int`|`Int`|`i8,i16,i32,i64`|\n|`uint`[`8`\u0026vert;`16`\u0026vert;`32`\u0026vert;`64`]|`number`|`int`|`Int`|`Int`|`u8,u16,u32,u64`|\n|`byte`(=`uint8`)|`number`|`int`|`Int`|`Int`|`i8`|\n|`rune`(=`int32`)|`number`|`dynamic`|`Any`|`Any`|`i32`|\n|`float`[`32`\u0026vert;`64`]|`number`|`double`|`Double`|`Double`|`f32,f64`|\n|`uintptr`|`any`|`dynamic`|`Any`|`Any`|`T4`|\n|`*`|`T \\| null`|`T?`|`T?`|`T?`|`Option\u003cT5\u003e`|\n\n## Differences between typex2 and typex\n\n1. Code legibility.\n   - Typex2 uses go's strengths in functional programming.\n   - It also improves separation of concerns, the reading of the go structs and types is separated from the generation of the types in said language.\n2. Generated code is instantly written to that same path instead of out putting it to the console.\n3. Pointers are possibly nil in go, thus implemented in Typex2.\n4. Ability to generate for other languages than TypeScript: Dart, Kotlin, Swift (it's only 300 lines to add a new language)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flil5%2Ftypex2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flil5%2Ftypex2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flil5%2Ftypex2/lists"}