0.5.0 • Published 1 year 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
1 year ago
0.4.5
4 years ago
0.4.4
4 years ago
0.4.3
4 years ago
0.4.2
5 years ago
0.4.1
5 years ago
0.4.0
5 years ago
0.3.3
5 years ago
0.3.2
5 years ago
0.3.1
5 years ago
0.3.0
5 years ago
0.2.2
5 years ago
0.2.1
6 years ago
0.2.0
6 years ago
0.1.11
6 years ago
0.1.10
6 years ago
0.1.9
6 years ago
0.1.8
6 years ago
0.1.7
6 years ago
0.1.6
6 years ago
0.1.5
6 years ago
0.1.4
6 years ago
0.1.3
6 years ago
0.1.2
6 years ago
0.1.1
6 years ago
0.1.0
6 years ago
0.0.4
6 years ago
0.0.3
7 years ago
0.0.2
7 years ago
0.0.1
7 years ago