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:
//Define a normal io-ts interface type //Derive a class from it //Define another io-ts interface type ; ; ; //person.MiddleName === null //person.FirstName === 'Test' //person.Address.StreetAddress1 === '' //person.Address.City.Name === '' ; ; //result.isLeft() === false //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