Reads a go package's types and export them to typescript interfaces and basic types.
This is the follow up of https://github.com/dtgorski/typex
go get -u github.com/lil5/typex2
$ typex2 ./examples
This will do the following;
- Read all go files inside the path specified (must use one package name).
- Generate typescript types and interfaces from said go files.
- Write generated content into
./examples/index.ts
.
copy from Typex readme
TypeScript (resp. JavaScript aka ECMAScript) lacks a native integer number type.
The numeric type provided there is inherently a 64 bit float.
You should keep this in mind when working with exported numeric types - this includes byte
and rune
type aliases as well.
Go native type | TypeScript type |
---|---|
bool |
boolean |
string |
string |
map |
Record<K, V> |
interface |
Record<string, any> |
struct (named) |
T |
struct (anonymous) |
{} |
array (slice) |
T[] |
complex [64 |128 ] |
any |
chan , func , interface |
any |
int [8 |16 |32 |64 ] |
number |
uint [8 |16 |32 |64 ] |
number |
byte (=uint8 ) |
number |
rune (=int32 ) |
number |
float [32 |64 ] |
number |
uintptr |
any |
* |
T | null |
- Code legibility.
- Typex2 uses go's strengths in functional programming.
- It also improves seperation of concerns, the reading of the go structs and types is seperated from the generation of the types in said language.
- Generated code is instantly written to that same path instead of out putting it to the console.
- Pointers are possibly nil in go, thus implemented in Typex2.