io-ts
Advanced tools
Comparing version 0.7.1 to 0.7.2
@@ -15,2 +15,7 @@ # Changelog | ||
# 0.7.2 | ||
- **Bug Fix** | ||
- tag recursive types, fix #80 (@gcanti) | ||
# 0.7.1 | ||
@@ -17,0 +22,0 @@ |
@@ -165,3 +165,11 @@ import { Either } from 'fp-ts/lib/Either'; | ||
}>(keys: D, name?: string | undefined) => KeyofType<D>; | ||
export declare const recursion: <T>(name: string, definition: (self: Type<any>) => Type<any>) => Type<T>; | ||
export declare class RecursiveType<T> implements Type<T> { | ||
readonly name: string; | ||
readonly validate: Validate<T>; | ||
readonly _tag: 'RecursiveType'; | ||
readonly _A: T; | ||
readonly type: Any; | ||
constructor(name: string, validate: Validate<T>); | ||
} | ||
export declare const recursion: <T>(name: string, definition: (self: Type<any>) => Type<any>) => RecursiveType<T>; | ||
export declare class ArrayType<RT extends Any> implements Type<Array<TypeOf<RT>>> { | ||
@@ -168,0 +176,0 @@ readonly type: RT; |
@@ -218,7 +218,16 @@ "use strict"; | ||
// | ||
var RecursiveType = /** @class */ (function () { | ||
function RecursiveType(name, validate) { | ||
this.name = name; | ||
this.validate = validate; | ||
this._tag = 'RecursiveType'; | ||
} | ||
return RecursiveType; | ||
}()); | ||
exports.RecursiveType = RecursiveType; | ||
exports.recursion = function (name, definition) { | ||
var Self = { name: name, validate: function (v, c) { return Result.validate(v, c); } }; | ||
var Result = definition(Self); | ||
Result.name = name; | ||
return Result; | ||
var Self = new RecursiveType(name, function (v, c) { return type.validate(v, c); }); | ||
var type = definition(Self); | ||
Self.type = type; | ||
return Self; | ||
}; | ||
@@ -225,0 +234,0 @@ // |
{ | ||
"name": "io-ts", | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"description": "TypeScript compatible runtime type system for IO validation", | ||
@@ -5,0 +5,0 @@ "files": ["lib"], |
@@ -166,2 +166,12 @@ # The idea | ||
# Refinements | ||
You can refine a type (_any_ type) using the `refinement` combinator | ||
```ts | ||
const Positive = t.refinement(t.number, n => n >= 0, 'Positive') | ||
const Adult = t.refinement(Person, person => person.age >= 18, 'Adult') | ||
``` | ||
# Mixing required and optional props | ||
@@ -168,0 +178,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
66628
824
347