https://github.com/justinwoo/purescript-ohyes
A library for generating Typescript types that can be used transparently from Purescript.
https://github.com/justinwoo/purescript-ohyes
codegen purescript types typescript
Last synced: about 1 month ago
JSON representation
A library for generating Typescript types that can be used transparently from Purescript.
- Host: GitHub
- URL: https://github.com/justinwoo/purescript-ohyes
- Owner: justinwoo
- License: mit
- Created: 2017-08-26T22:25:08.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-17T09:46:21.000Z (almost 6 years ago)
- Last Synced: 2025-03-17T18:48:39.492Z (about 1 month ago)
- Topics: codegen, purescript, types, typescript
- Language: PureScript
- Size: 14.6 KB
- Stars: 68
- Watchers: 4
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Purescript-OhYes
[](https://travis-ci.org/justinwoo/purescript-ohyes)
A library for generating Typescript types that can be used transparently from Purescript.
See the blog post here:
This is likely not the "silver bullet" that you are looking for, but can give you some good ideas on how to get going.

This library also provides ways for working with typical union type forms of records with a discriminant field by using [Variant](https://github.com/natefaubion/purescript-variant), which uses a record representation with a string literal `type` field and the associated `value` field.
```ts
export type VariantTest =
| { type: "a", value: string }
| { type: "b", value: number }
| { type: "c", value: boolean };
```## Example
The [tests](test/Main.purs) generate types and write them to a file, which is then checked with Typescript using [test/test.ts](test/test.ts):
```hs
type A =
{ a :: Number
, b :: String
, c :: { d :: String }
, e :: Array String
, f :: Nullable String
, g :: Number -> Number -> Number
, h :: Fn2 Number Number Number
, i :: Fn2 Number (Fn2 Number Number Number) Number
}type VariantTest = Variant
( a :: String
, b :: Number
, c :: Boolean
)generateTSFile :: _
generateTSFile = writeTextFile UTF8 "./test/generated.ts" values
where
values = format defaultOptions $ intercalate "\n"
[ generateTS "A" (Proxy :: Proxy A)
, generateTS "VariantTest" (Proxy :: Proxy VariantTest)
]
```Generated types:
```ts
export type A = {
a: number,
b: string,
c: { d: string },
e: string[],
f: string | null,
g: (a: number) => (a: number) => number,
h: (a: number, b: number) => number,
i: (a: number, b: (a: number, b: number) => number) => number
};
export type VariantTest =
| { type: "a", value: string }
| { type: "b", value: number }
| { type: "c", value: boolean };
```See the additional example here: https://github.com/justinwoo/ohyes-demo