cuetypescript

package module
v0.0.0-...-ff13663 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: GPL-3.0 Imports: 2 Imported by: 1

README

Cue + TypeScript


This package converts Cue types to TypeScript types, and soon vice-versa.

Cue is a concise language for defining types and constraints in one file. It's best practice to have a single source of truth for your types. This package allows you to convert your Cue types to TypeScript for the frontend.

Usage

This is a library for converting cue types, intended for use within a go application. Run the following command to install the package:

go get github.com/inngest/cuetypescript

Examples

CUETypeScript
#Post: {
	id:        string
	slug:      string
	title:     string
	subtitle?: string
	rating:    float & <=5
	category:  "tech" | "finance" | "hr"
	tags: [...string]
	references: [...{
		slug:  string
		title: string
	}]
}
export const Category = {
  TECH: "tech",
  FINANCE: "finance",
  HR: "hr",
} as const;
export type Category = typeof Category[keyof typeof Category];

export interface Post {
  id: string;
  slug: string;
  title: string;
  subtitle?: string;
  rating: number;
  category: Category;
  tags: Array<string>;
  references: Array<{
    slug: string;
    title: string;
  }>;
};

Features

  • Interface generation
  • Type conversion and support
  • Nested struct support
  • Union support
  • "Best practice" enum generation. We create enums with both const and type values, allowing you to properly reference enum values via eg. Category.TECH.

In the future, we plan on adding:

  • Function generation for checking and validating Cue constraints
  • Default value generation and constructors
  • Typescript to Cue support

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalCueValue

func MarshalCueValue(v cue.Value) (string, error)

MarshalCueValue returns a typescript type given a cue value.

func MarshalString

func MarshalString(cuestr string) (string, error)

MarshalString marshals a Cue string into a Typescript type string, returning an error.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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