Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inngest/cuetypescript
Converts Cue types to TypeScript types and vice-versa.
https://github.com/inngest/cuetypescript
cue cuelang typescript typescript-type-tool typescript-types
Last synced: about 1 month ago
JSON representation
Converts Cue types to TypeScript types and vice-versa.
- Host: GitHub
- URL: https://github.com/inngest/cuetypescript
- Owner: inngest
- License: gpl-3.0
- Archived: true
- Created: 2022-02-25T21:22:49.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-06T19:14:10.000Z (about 1 year ago)
- Last Synced: 2024-07-27T08:33:47.355Z (about 2 months ago)
- Topics: cue, cuelang, typescript, typescript-type-tool, typescript-types
- Language: Go
- Homepage:
- Size: 70.3 KB
- Stars: 16
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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
```cue
#Post: {
id: string
slug: string
title: string
subtitle?: string
rating: float & <=5
category: "tech" | "finance" | "hr"
tags: [...string]
references: [...{
slug: string
title: string
}]
}
``````typescript
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;
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