New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ts-to-io

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-to-io

Converts TypeScript type and interface definitions into [io-ts](https://github.com/gcanti/io-ts) type validators.

  • 0.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.3K
decreased by-16.48%
Maintainers
1
Weekly downloads
 
Created
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

Package 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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc