Categorygithub.com/lil5/typex2
repositorypackage
1.1.0
Repository: https://github.com/lil5/typex2.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

Go Go Report Card Coverage Status

TypeX 2

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

Installation

go get -u github.com/lil5/typex2

Usage

$ typex2 ./examples

This will do the following;

  1. Read all go files inside the path specified (must use one package name).
  2. Generate typescript types and interfaces from said go files.
  3. Write generated content into ./examples/index.ts.

TypeScript type mapping

copy from Typex readme

https://github.com/dtgorski/typex#typescript-type-mapping

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 typeTypeScript type
boolboolean
stringstring
mapRecord<K, V>
interfaceRecord<string, any>
struct (named)T
struct (anonymous){}
array (slice)T[]
complex[64|128]any
chan, func, interfaceany
int[8|16|32|64]number
uint[8|16|32|64]number
byte(=uint8)number
rune(=int32)number
float[32|64]number
uintptrany
*T | null

Differences between typex2 and typex

  1. 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.
  2. Generated code is instantly written to that same path instead of out putting it to the console.
  3. Pointers are possibly nil in go, thus implemented in Typex2.