tsgen

package module
v0.0.0-...-5d3802e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2023 License: MIT Imports: 0 Imported by: 0

README

TSGen

Typescript generator for Go.

Inspired and copied from Dave Brophy's Jennifer project.

package main

import (
    "fmt"

    . "github.com/seamusv/tsgen/gen"
)

func main() {
	f := NewFile(WithPrettierFormatter())

	f.ImportDefault("react", "React")

	f.Interface().Id("Props").Values(Dict{
		Id("name"): Id("string"),
	})

	f.Line()

	f.Export().Const().Id("MyComponent").Op("=").Params(Dict{Id("props"): Id("Props")}).Op("=>").Block(
		Return(Id("<div>Welcome to the Jungle, {props.name}!</div>")),
	)
	fmt.Printf("%#v", f)
}

Output:

import * as React from 'react';

interface Props {
    name: string;
}

export const MyComponent = (props: Props) => {
    return <div>Welcome to the Jungle, {props.name}!</div>;
};
Install
go get -u github.com/seamusv/tsgen/tsgen

WIP

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL