tti

ts-to-io

Transform TypeScript types to io-ts runtime validator codecs

Showing:

Popularity

Downloads/wk

104

GitHub Stars

95

Maintenance

Last Commit

1yr ago

Contributors

5

Package

Dependencies

2

Size (min+gzip)

697.2KB

License

MIT

Type Definitions

Built-In

Tree-Shakeable

No?

Categories

Readme

ts-to-io

Converts TypeScript type and interface definitions into io-ts type validators.

Usage

As a script

$ npm install -g ts-to-io
$ ts-to-io file.ts

or

$ npx ts-to-io file.ts

From code

NOTE: The validator generation is not intended to be performed at runtime. You should first generate the validators locally and then include them in the program source.

import { getValidatorsFromString } from "ts-to-io"

const sourceString = `
  type Person = { name: string; age: number | null }
`

const validators = getValidatorsFromString(sourceString)

Configuration

ts-to-io supports the following config options

KeyCLI optDefaultDescription
followImports--follow-importsfalseoutput codecs for types declared in imported files
includeHeader--no-include-headertrueomit io-ts import from the output

Supported types

TypeSupportedTypeScriptcodec
stringstringt.string
numbernumbert.number
booleanbooleant.boolean
nullnullt.null
undefinedundefinedt.undefined
voidvoidt.void
any, unknownany, unknownt.unknown
arrayArray<A>t.array(A)
recordRecord<K, A>t.record(K, A)
object type{ name: string }t.type({ name: t.string })
interfaceinterface I { name: string }t.type({ name: t.string })
literal'ABC't.literal('ABC')
partialPartial<{ name: string }>t.partial({ name: t.string })
readonlyReadonly<A>-
readonly arrayReadonlyArray<A>-
tuple[ A, B ]t.tuple([ A, B ])
tuple with rest[ A, B, ...C ]-
unionA \| Bt.union([ A, B ])
intersectionA & Bt.intersection([ A, B ])
keyofkeyof M-
recursive typetype Node = { children: Node[] }-
functiontype fn = () => stringt.Function

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial