Skip to content
 
 

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tsreflect

Build Status Codecov Go Report Card GoDoc

Flexible reflection based TypeScript type generator for Go types that can be marshalled with encoding/json.

Install

go get github.com/olahol/tsreflect

Example

package main

import (
	"fmt"
	"reflect"
	"strings"

	"github.com/olahol/tsreflect"
)

type MyStruct struct {
	Number int
	String int    `json:",string"`
	Alias  string `json:"alias"`
	Hidden string `json:"-"`
}

func main() {
	g := tsreflect.New()

	var x MyStruct
	typ := reflect.TypeOf(x)

	g.Add(typ)

	value, _ := json.Marshal(x)

	fmt.Println(g.DeclarationsTypeScript())
	fmt.Printf("const x: %s = %s", g.TypeOf(typ), value)
	// Output:
	// interface MyStruct { "Number": number; "String": string; "alias": string; }
	// const x: MyStruct = {"Number":0,"String":"0","alias":""}
}

About

Flexible reflection based TypeScript type generator for Go types that can be marshalled with `encoding/json`.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages