Socket
Socket
Sign inDemoInstall

ts-to-io

Package Overview
Dependencies
2
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-to-io


Version published
Maintainers
1
Created

Readme

Source

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

FAQs

Last updated on 20 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc