# io-ts-codegen

> Code generation for io-ts

Latest version **0.5.0** (published 2023-02-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install io-ts-codegen
pnpm add io-ts-codegen
yarn add io-ts-codegen
bun add io-ts-codegen
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2023-02-24 |
| First published | 2017-06-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 39 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 159 |
| Author | Giulio Canti |
| Maintainers | gcanti |
| Keywords | typescript, io-ts, code-generation |

## Links

- npm: https://www.npmjs.com/package/io-ts-codegen
- Repository: https://github.com/gcanti/io-ts-codegen
- Issues: https://github.com/gcanti/io-ts-codegen/issues
- npm.io page: https://npm.io/package/io-ts-codegen

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.5.0 (latest) — 2023-02-24
- 0.4.5 — 2020-06-27
- 0.4.4 — 2020-04-30
- 0.4.3 — 2020-01-19
- 0.4.2 — 2019-09-25
- 0.4.1 — 2019-07-23
- 0.4.0 — 2019-07-18
- 0.3.3 — 2019-04-02
- 0.3.2 — 2019-02-07
- 0.3.1 — 2019-02-06
- 0.3.0 — 2019-01-29
- 0.2.2 — 2018-12-17
- 0.2.1 — 2018-10-23
- 0.2.0 — 2018-09-03
- 0.1.11 — 2018-07-22
- … 15 more at https://npm.io/package/io-ts-codegen/versions

## README

# Motivation

Generate both static and runtime types from an intermediate language.

The intermediate language can in turn be generated from other schemas: JSON Schema, Swagger, [metarpheus](https://github.com/buildo/metarpheus), etc..

# `io-ts` compatibility

| `io-ts-codegen` version | target `io-ts` version |
| ----------------------- | ---------------------- |
| 0.4.0+                  | 1.0.0+ \|\| 2.0.0+     |
| 0.3.0+                  | 1.0.0+ \|\| 2.0.0+     |

# Usage

Nodes of the intermediate language can be built from the provided builders.

```ts
import * as gen from 'io-ts-codegen'

// list of type declarations
const declarations = [
  gen.typeDeclaration('Persons', gen.arrayCombinator(gen.identifier('Person'))),
  gen.typeDeclaration(
    'Person',
    gen.typeCombinator([gen.property('name', gen.stringType), gen.property('age', gen.numberType)])
  )
]

// apply topological sort in order to get the right order
const sorted = gen.sort(declarations)

console.log(sorted.map(d => gen.printRuntime(d)).join('\n'))
console.log(sorted.map(d => gen.printStatic(d)).join('\n'))
```

Output (as string)

```ts
const Person = t.type({
  name: t.string,
  age: t.number
})
const Persons = t.array(Person)
interface Person {
  name: string
  age: number
}
type Persons = Array<t.TypeOf<typeof Person>>
```

# Documentation

- [API Reference](https://gcanti.github.io/io-ts-codegen)

---
_Source: https://npm.io/package/io-ts-codegen · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
