Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.
/ typex2 Public archive

Reads a go package's types and export them to typescript interfaces and basic types.

License

Notifications You must be signed in to change notification settings

lil5/typex2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Workflow Status (branch) 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 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

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.