
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
io-ts-derive-class
Advanced tools
Getting Started
yarn add io-ts-derive-class io-ts
Purpose:
This library is intended to help create classes from io-ts interface types and assist in setting defaults on instances of these classes.
Quick Example:
import * as t from 'io-ts'
import * as tdc from 'io-ts-derive-class'
//Define a normal io-ts interface type
const CityType = t.type({
ID: t.number,
Name: t.string
})
//Derive a class from it
class City extends tdc.DeriveClass(CityType) {}
//Define another io-ts interface type
const AddressType = t.type({
StreetAddress1: t.string,
StreetAddress2: t.string,
//Reference the previously defined class
City: tdc.ref(City)
});
class Address extends tdc.DeriveClass(AddressType) {}
const PersonType = t.type({
ID: t.number,
FirstName: t.string,
//MiddleName is string or null. The default generated will be the right most member of the union. Here it will be null.
MiddleName: t.union([t.string, t.null]),
LastName: t.string,
Address: tdc.ref(Address)
});
class Person extends tdc.DeriveClass(PersonType) {}
const person = new Person({
FirstName: 'Test',
LastName: 'TestLast'
});
//person.MiddleName === null
//person.FirstName === 'Test'
//person.Address.StreetAddress1 === ''
//person.Address.City.Name === ''
const personJson = JSON.stringify(person);
const result = tdc.decode(Person, personJson);
//result.isLeft() === false
const areEqual = JSON.stringify(result.value) === personJson
//areEqual === true
Derived Defaults:
unions will always default to the right most type
| Type | Default Value |
|---|---|
| t.number | 0 |
| t.string | '' |
| t.undefined | undefined |
| t.null | null |
| t.boolean | false |
| t.literal('myliteral') | 'myliteral' |
| t.union([t.string, t.undefined]) | undefined |
| t.union([t.string, t.null]) | null |
| t.union([t.number, t.string]) | '' |
| t.type({}) | {} |
| t.tuple([t.string, t.number]) | ['', 0] |
| t.array(arraytype) | [] |
| tdc.ref(MyClass) | new MyClass() |
| tdc.DateTime | moment() |
| tdc.uuid | creates uuid4 |
More examples and tests can be found in src/index.spec.ts
Contributing:
yarn install
yarn run test
FAQs
Getting Started
The npm package io-ts-derive-class receives a total of 5 weekly downloads. As such, io-ts-derive-class popularity was classified as not popular.
We found that io-ts-derive-class demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.