0.5.0 • Published 2 years ago
io-ts-codegen v0.5.0
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, 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.
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)
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
0.5.0
2 years ago
0.4.5
5 years ago
0.4.4
5 years ago
0.4.3
5 years ago
0.4.2
6 years ago
0.4.1
6 years ago
0.4.0
6 years ago
0.3.3
6 years ago
0.3.2
6 years ago
0.3.1
6 years ago
0.3.0
6 years ago
0.2.2
6 years ago
0.2.1
7 years ago
0.2.0
7 years ago
0.1.11
7 years ago
0.1.10
7 years ago
0.1.9
7 years ago
0.1.8
7 years ago
0.1.7
7 years ago
0.1.6
7 years ago
0.1.5
7 years ago
0.1.4
7 years ago
0.1.3
7 years ago
0.1.2
7 years ago
0.1.1
7 years ago
0.1.0
7 years ago
0.0.4
8 years ago
0.0.3
8 years ago
0.0.2
8 years ago
0.0.1
8 years ago