Comparing version 1.3.0 to 1.3.1
@@ -16,2 +16,11 @@ # Changelog | ||
# 1.3.1 | ||
- **Polish** | ||
- use interface instead of type alias (@gcanti) | ||
- `Context` | ||
- `Errors` | ||
- `Any` | ||
- `Mixed` | ||
# 1.3.0 | ||
@@ -18,0 +27,0 @@ |
@@ -15,3 +15,4 @@ import { Either } from 'fp-ts/lib/Either'; | ||
} | ||
export declare type Context = ReadonlyArray<ContextEntry>; | ||
export interface Context extends ReadonlyArray<ContextEntry> { | ||
} | ||
export interface ValidationError { | ||
@@ -21,3 +22,4 @@ readonly value: mixed; | ||
} | ||
export declare type Errors = Array<ValidationError>; | ||
export interface Errors extends Array<ValidationError> { | ||
} | ||
export declare type Validation<A> = Either<Errors, A>; | ||
@@ -28,4 +30,6 @@ export declare type Is<A> = (m: mixed) => m is A; | ||
export declare type Encode<A, O> = (a: A) => O; | ||
export declare type Any = Type<any, any, any>; | ||
export declare type Mixed = Type<any, any, mixed>; | ||
export interface Any extends Type<any, any, any> { | ||
} | ||
export interface Mixed extends Type<any, any, mixed> { | ||
} | ||
export declare type TypeOf<RT extends Any> = RT['_A']; | ||
@@ -72,8 +76,8 @@ export declare type InputOf<RT extends Any> = RT['_I']; | ||
export declare const getContextEntry: (key: string, type: Decoder<any, any>) => ContextEntry; | ||
export declare const getValidationError: (value: mixed, context: ReadonlyArray<ContextEntry>) => ValidationError; | ||
export declare const getDefaultContext: (type: Decoder<any, any>) => ReadonlyArray<ContextEntry>; | ||
export declare const appendContext: (c: ReadonlyArray<ContextEntry>, key: string, type: Decoder<any, any>) => ReadonlyArray<ContextEntry>; | ||
export declare const failures: <T>(errors: ValidationError[]) => Either<ValidationError[], T>; | ||
export declare const failure: <T>(value: mixed, context: ReadonlyArray<ContextEntry>) => Either<ValidationError[], T>; | ||
export declare const success: <T>(value: T) => Either<ValidationError[], T>; | ||
export declare const getValidationError: (value: mixed, context: Context) => ValidationError; | ||
export declare const getDefaultContext: (type: Decoder<any, any>) => Context; | ||
export declare const appendContext: (c: Context, key: string, type: Decoder<any, any>) => Context; | ||
export declare const failures: <T>(errors: Errors) => Either<Errors, T>; | ||
export declare const failure: <T>(value: mixed, context: Context) => Either<Errors, T>; | ||
export declare const success: <T>(value: T) => Either<Errors, T>; | ||
export declare class NullType extends Type<null> { | ||
@@ -147,5 +151,5 @@ readonly _tag: 'NullType'; | ||
readonly _tag: 'RefinementType'; | ||
constructor(name: string, is: RefinementType<RT, A, O, I>['is'], validate: RefinementType<RT, A, O, I>['validate'], serialize: RefinementType<RT, A, O, I>['encode'], type: RT, predicate: Predicate<A>); | ||
constructor(name: string, is: RefinementType<RT, A, O, I>['is'], validate: RefinementType<RT, A, O, I>['validate'], encode: RefinementType<RT, A, O, I>['encode'], type: RT, predicate: Predicate<A>); | ||
} | ||
export declare const refinement: <RT extends Type<any, any, any>>(type: RT, predicate: Predicate<RT["_A"]>, name?: string) => RefinementType<RT, RT["_A"], RT["_O"], RT["_I"]>; | ||
export declare const refinement: <RT extends Any>(type: RT, predicate: Predicate<RT["_A"]>, name?: string) => RefinementType<RT, RT["_A"], RT["_O"], RT["_I"]>; | ||
export declare const Integer: RefinementType<NumberType, number, number, mixed>; | ||
@@ -155,3 +159,3 @@ export declare class LiteralType<V extends string | number | boolean> extends Type<V> { | ||
readonly _tag: 'LiteralType'; | ||
constructor(name: string, is: LiteralType<V>['is'], validate: LiteralType<V>['validate'], serialize: LiteralType<V>['encode'], value: V); | ||
constructor(name: string, is: LiteralType<V>['is'], validate: LiteralType<V>['validate'], encode: LiteralType<V>['encode'], value: V); | ||
} | ||
@@ -164,3 +168,3 @@ export declare const literal: <V extends string | number | boolean>(value: V, name?: string) => LiteralType<V>; | ||
readonly _tag: 'KeyofType'; | ||
constructor(name: string, is: KeyofType<D>['is'], validate: KeyofType<D>['validate'], serialize: KeyofType<D>['encode'], keys: D); | ||
constructor(name: string, is: KeyofType<D>['is'], validate: KeyofType<D>['validate'], encode: KeyofType<D>['encode'], keys: D); | ||
} | ||
@@ -173,3 +177,3 @@ export declare const keyof: <D extends { | ||
readonly _tag: 'RecursiveType'; | ||
constructor(name: string, is: RecursiveType<RT, A, O, I>['is'], validate: RecursiveType<RT, A, O, I>['validate'], serialize: RecursiveType<RT, A, O, I>['encode'], runDefinition: () => RT); | ||
constructor(name: string, is: RecursiveType<RT, A, O, I>['is'], validate: RecursiveType<RT, A, O, I>['validate'], encode: RecursiveType<RT, A, O, I>['encode'], runDefinition: () => RT); | ||
readonly type: RT; | ||
@@ -181,9 +185,9 @@ } | ||
readonly _tag: 'ArrayType'; | ||
constructor(name: string, is: ArrayType<RT, A, O, I>['is'], validate: ArrayType<RT, A, O, I>['validate'], serialize: ArrayType<RT, A, O, I>['encode'], type: RT); | ||
constructor(name: string, is: ArrayType<RT, A, O, I>['is'], validate: ArrayType<RT, A, O, I>['validate'], encode: ArrayType<RT, A, O, I>['encode'], type: RT); | ||
} | ||
export declare const array: <RT extends Type<any, any, mixed>>(type: RT, name?: string) => ArrayType<RT, RT["_A"][], RT["_O"][], mixed>; | ||
export declare const array: <RT extends Mixed>(type: RT, name?: string) => ArrayType<RT, RT["_A"][], RT["_O"][], mixed>; | ||
export declare class InterfaceType<P, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
readonly props: P; | ||
readonly _tag: 'InterfaceType'; | ||
constructor(name: string, is: InterfaceType<P, A, O, I>['is'], validate: InterfaceType<P, A, O, I>['validate'], serialize: InterfaceType<P, A, O, I>['encode'], props: P); | ||
constructor(name: string, is: InterfaceType<P, A, O, I>['is'], validate: InterfaceType<P, A, O, I>['validate'], encode: InterfaceType<P, A, O, I>['encode'], props: P); | ||
} | ||
@@ -207,3 +211,3 @@ export interface AnyProps { | ||
readonly _tag: 'PartialType'; | ||
constructor(name: string, is: PartialType<P, A, O, I>['is'], validate: PartialType<P, A, O, I>['validate'], serialize: PartialType<P, A, O, I>['encode'], props: P); | ||
constructor(name: string, is: PartialType<P, A, O, I>['is'], validate: PartialType<P, A, O, I>['validate'], encode: PartialType<P, A, O, I>['encode'], props: P); | ||
} | ||
@@ -221,3 +225,3 @@ export declare type TypeOfPartialProps<P extends AnyProps> = { | ||
readonly _tag: 'DictionaryType'; | ||
constructor(name: string, is: DictionaryType<D, C, A, O, I>['is'], validate: DictionaryType<D, C, A, O, I>['validate'], serialize: DictionaryType<D, C, A, O, I>['encode'], domain: D, codomain: C); | ||
constructor(name: string, is: DictionaryType<D, C, A, O, I>['is'], validate: DictionaryType<D, C, A, O, I>['validate'], encode: DictionaryType<D, C, A, O, I>['encode'], domain: D, codomain: C); | ||
} | ||
@@ -230,13 +234,13 @@ export declare type TypeOfDictionary<D extends Any, C extends Any> = { | ||
}; | ||
export declare const dictionary: <D extends Type<any, any, mixed>, C extends Type<any, any, mixed>>(domain: D, codomain: C, name?: string) => DictionaryType<D, C, TypeOfDictionary<D, C>, OutputOfDictionary<D, C>, mixed>; | ||
export declare const dictionary: <D extends Mixed, C extends Mixed>(domain: D, codomain: C, name?: string) => DictionaryType<D, C, TypeOfDictionary<D, C>, OutputOfDictionary<D, C>, mixed>; | ||
export declare class UnionType<RTS extends Array<Any>, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
readonly types: RTS; | ||
readonly _tag: 'UnionType'; | ||
constructor(name: string, is: UnionType<RTS, A, O, I>['is'], validate: UnionType<RTS, A, O, I>['validate'], serialize: UnionType<RTS, A, O, I>['encode'], types: RTS); | ||
constructor(name: string, is: UnionType<RTS, A, O, I>['is'], validate: UnionType<RTS, A, O, I>['validate'], encode: UnionType<RTS, A, O, I>['encode'], types: RTS); | ||
} | ||
export declare const union: <RTS extends Type<any, any, mixed>[]>(types: RTS, name?: string) => UnionType<RTS, RTS["_A"]["_A"], RTS["_A"]["_O"], mixed>; | ||
export declare const union: <RTS extends Mixed[]>(types: RTS, name?: string) => UnionType<RTS, RTS["_A"]["_A"], RTS["_A"]["_O"], mixed>; | ||
export declare class IntersectionType<RTS extends Array<Any>, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
readonly types: RTS; | ||
readonly _tag: 'IntersectionType'; | ||
constructor(name: string, is: IntersectionType<RTS, A, O, I>['is'], validate: IntersectionType<RTS, A, O, I>['validate'], serialize: IntersectionType<RTS, A, O, I>['encode'], types: RTS); | ||
constructor(name: string, is: IntersectionType<RTS, A, O, I>['is'], validate: IntersectionType<RTS, A, O, I>['validate'], encode: IntersectionType<RTS, A, O, I>['encode'], types: RTS); | ||
} | ||
@@ -251,3 +255,3 @@ export declare function intersection<A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed, E extends Mixed>(types: [A, B, C, D, E], name?: string): IntersectionType<[A, B, C, D, E], TypeOf<A> & TypeOf<B> & TypeOf<C> & TypeOf<D> & TypeOf<E>, OutputOf<A> & OutputOf<B> & OutputOf<C> & OutputOf<D> & OutputOf<E>, mixed>; | ||
readonly _tag: 'TupleType'; | ||
constructor(name: string, is: TupleType<RTS, A, O, I>['is'], validate: TupleType<RTS, A, O, I>['validate'], serialize: TupleType<RTS, A, O, I>['encode'], types: RTS); | ||
constructor(name: string, is: TupleType<RTS, A, O, I>['is'], validate: TupleType<RTS, A, O, I>['validate'], encode: TupleType<RTS, A, O, I>['encode'], types: RTS); | ||
} | ||
@@ -262,15 +266,15 @@ export declare function tuple<A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed, E extends Mixed>(types: [A, B, C, D, E], name?: string): TupleType<[A, B, C, D, E], [TypeOf<A>, TypeOf<B>, TypeOf<C>, TypeOf<D>, TypeOf<E>], [OutputOf<A>, OutputOf<B>, OutputOf<C>, OutputOf<D>, OutputOf<E>], mixed>; | ||
readonly _tag: 'ReadonlyType'; | ||
constructor(name: string, is: ReadonlyType<RT, A, O, I>['is'], validate: ReadonlyType<RT, A, O, I>['validate'], serialize: ReadonlyType<RT, A, O, I>['encode'], type: RT); | ||
constructor(name: string, is: ReadonlyType<RT, A, O, I>['is'], validate: ReadonlyType<RT, A, O, I>['validate'], encode: ReadonlyType<RT, A, O, I>['encode'], type: RT); | ||
} | ||
export declare const readonly: <RT extends Type<any, any, mixed>>(type: RT, name?: string) => ReadonlyType<RT, Readonly<RT["_A"]>, Readonly<RT["_O"]>, mixed>; | ||
export declare const readonly: <RT extends Mixed>(type: RT, name?: string) => ReadonlyType<RT, Readonly<RT["_A"]>, Readonly<RT["_O"]>, mixed>; | ||
export declare class ReadonlyArrayType<RT extends Any, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
readonly type: RT; | ||
readonly _tag: 'ReadonlyArrayType'; | ||
constructor(name: string, is: ReadonlyArrayType<RT, A, O, I>['is'], validate: ReadonlyArrayType<RT, A, O, I>['validate'], serialize: ReadonlyArrayType<RT, A, O, I>['encode'], type: RT); | ||
constructor(name: string, is: ReadonlyArrayType<RT, A, O, I>['is'], validate: ReadonlyArrayType<RT, A, O, I>['validate'], encode: ReadonlyArrayType<RT, A, O, I>['encode'], type: RT); | ||
} | ||
export declare const readonlyArray: <RT extends Type<any, any, mixed>>(type: RT, name?: string) => ReadonlyArrayType<RT, ReadonlyArray<RT["_A"]>, ReadonlyArray<RT["_O"]>, mixed>; | ||
export declare const readonlyArray: <RT extends Mixed>(type: RT, name?: string) => ReadonlyArrayType<RT, ReadonlyArray<RT["_A"]>, ReadonlyArray<RT["_O"]>, mixed>; | ||
export declare class StrictType<P, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
readonly props: P; | ||
readonly _tag: 'StrictType'; | ||
constructor(name: string, is: StrictType<P, A, O, I>['is'], validate: StrictType<P, A, O, I>['validate'], serialize: StrictType<P, A, O, I>['encode'], props: P); | ||
constructor(name: string, is: StrictType<P, A, O, I>['is'], validate: StrictType<P, A, O, I>['validate'], encode: StrictType<P, A, O, I>['encode'], props: P); | ||
} | ||
@@ -295,7 +299,7 @@ /** | ||
export declare type Tagged<Tag extends string, A = any, O = A> = InterfaceType<TaggedProps<Tag>, A, O> | StrictType<TaggedProps<Tag>, A, O> | TaggedRefinement<Tag, A, O> | TaggedUnion<Tag, A, O> | TaggedIntersection<Tag, A, O> | TaggedExact<Tag> | RecursiveType<any, A, O>; | ||
export declare const isTagged: <Tag extends string>(tag: Tag) => (type: Type<any, any, mixed>) => type is Tagged<Tag, any, any>; | ||
export declare const isTagged: <Tag extends string>(tag: Tag) => (type: Mixed) => type is Tagged<Tag, any, any>; | ||
export declare const getTagValue: <Tag extends string>(tag: Tag) => (type: Tagged<Tag, any, any>) => string | number | boolean; | ||
export declare class TaggedUnionType<Tag extends string, RTS extends Array<Tagged<Tag>>, A = any, O = A, I = mixed> extends UnionType<RTS, A, O, I> { | ||
readonly tag: Tag; | ||
constructor(name: string, is: TaggedUnionType<Tag, RTS, A, O, I>['is'], validate: TaggedUnionType<Tag, RTS, A, O, I>['validate'], serialize: TaggedUnionType<Tag, RTS, A, O, I>['encode'], types: RTS, tag: Tag); | ||
constructor(name: string, is: TaggedUnionType<Tag, RTS, A, O, I>['is'], validate: TaggedUnionType<Tag, RTS, A, O, I>['validate'], encode: TaggedUnionType<Tag, RTS, A, O, I>['encode'], types: RTS, tag: Tag); | ||
} | ||
@@ -306,3 +310,3 @@ export declare const taggedUnion: <Tag extends string, RTS extends Tagged<Tag, any, any>[]>(tag: Tag, types: RTS, name?: string) => TaggedUnionType<Tag, RTS, RTS["_A"]["_A"], RTS["_A"]["_O"], mixed>; | ||
readonly _tag: 'ExactType'; | ||
constructor(name: string, is: ExactType<RT, A, O, I>['is'], validate: ExactType<RT, A, O, I>['validate'], serialize: ExactType<RT, A, O, I>['encode'], type: RT); | ||
constructor(name: string, is: ExactType<RT, A, O, I>['is'], validate: ExactType<RT, A, O, I>['validate'], encode: ExactType<RT, A, O, I>['encode'], type: RT); | ||
} | ||
@@ -309,0 +313,0 @@ export interface HasPropsRefinement extends RefinementType<HasProps, any, any, any> { |
@@ -247,4 +247,4 @@ "use strict"; | ||
__extends(RefinementType, _super); | ||
function RefinementType(name, is, validate, serialize, type, predicate) { | ||
var _this = _super.call(this, name, is, validate, serialize) || this; | ||
function RefinementType(name, is, validate, encode, type, predicate) { | ||
var _this = _super.call(this, name, is, validate, encode) || this; | ||
_this.type = type; | ||
@@ -277,4 +277,4 @@ _this.predicate = predicate; | ||
__extends(LiteralType, _super); | ||
function LiteralType(name, is, validate, serialize, value) { | ||
var _this = _super.call(this, name, is, validate, serialize) || this; | ||
function LiteralType(name, is, validate, encode, value) { | ||
var _this = _super.call(this, name, is, validate, encode) || this; | ||
_this.value = value; | ||
@@ -297,4 +297,4 @@ _this._tag = 'LiteralType'; | ||
__extends(KeyofType, _super); | ||
function KeyofType(name, is, validate, serialize, keys) { | ||
var _this = _super.call(this, name, is, validate, serialize) || this; | ||
function KeyofType(name, is, validate, encode, keys) { | ||
var _this = _super.call(this, name, is, validate, encode) || this; | ||
_this.keys = keys; | ||
@@ -317,4 +317,4 @@ _this._tag = 'KeyofType'; | ||
__extends(RecursiveType, _super); | ||
function RecursiveType(name, is, validate, serialize, runDefinition) { | ||
var _this = _super.call(this, name, is, validate, serialize) || this; | ||
function RecursiveType(name, is, validate, encode, runDefinition) { | ||
var _this = _super.call(this, name, is, validate, encode) || this; | ||
_this.runDefinition = runDefinition; | ||
@@ -350,4 +350,4 @@ _this._tag = 'RecursiveType'; | ||
__extends(ArrayType, _super); | ||
function ArrayType(name, is, validate, serialize, type) { | ||
var _this = _super.call(this, name, is, validate, serialize) || this; | ||
function ArrayType(name, is, validate, encode, type) { | ||
var _this = _super.call(this, name, is, validate, encode) || this; | ||
_this.type = type; | ||
@@ -397,4 +397,4 @@ _this._tag = 'ArrayType'; | ||
__extends(InterfaceType, _super); | ||
function InterfaceType(name, is, validate, serialize, props) { | ||
var _this = _super.call(this, name, is, validate, serialize) || this; | ||
function InterfaceType(name, is, validate, encode, props) { | ||
var _this = _super.call(this, name, is, validate, encode) || this; | ||
_this.props = props; | ||
@@ -486,4 +486,4 @@ _this._tag = 'InterfaceType'; | ||
__extends(PartialType, _super); | ||
function PartialType(name, is, validate, serialize, props) { | ||
var _this = _super.call(this, name, is, validate, serialize) || this; | ||
function PartialType(name, is, validate, encode, props) { | ||
var _this = _super.call(this, name, is, validate, encode) || this; | ||
_this.props = props; | ||
@@ -525,4 +525,4 @@ _this._tag = 'PartialType'; | ||
__extends(DictionaryType, _super); | ||
function DictionaryType(name, is, validate, serialize, domain, codomain) { | ||
var _this = _super.call(this, name, is, validate, serialize) || this; | ||
function DictionaryType(name, is, validate, encode, domain, codomain) { | ||
var _this = _super.call(this, name, is, validate, encode) || this; | ||
_this.domain = domain; | ||
@@ -594,4 +594,4 @@ _this.codomain = codomain; | ||
__extends(UnionType, _super); | ||
function UnionType(name, is, validate, serialize, types) { | ||
var _this = _super.call(this, name, is, validate, serialize) || this; | ||
function UnionType(name, is, validate, encode, types) { | ||
var _this = _super.call(this, name, is, validate, encode) || this; | ||
_this.types = types; | ||
@@ -638,4 +638,4 @@ _this._tag = 'UnionType'; | ||
__extends(IntersectionType, _super); | ||
function IntersectionType(name, is, validate, serialize, types) { | ||
var _this = _super.call(this, name, is, validate, serialize) || this; | ||
function IntersectionType(name, is, validate, encode, types) { | ||
var _this = _super.call(this, name, is, validate, encode) || this; | ||
_this.types = types; | ||
@@ -682,4 +682,4 @@ _this._tag = 'IntersectionType'; | ||
__extends(TupleType, _super); | ||
function TupleType(name, is, validate, serialize, types) { | ||
var _this = _super.call(this, name, is, validate, serialize) || this; | ||
function TupleType(name, is, validate, encode, types) { | ||
var _this = _super.call(this, name, is, validate, encode) || this; | ||
_this.types = types; | ||
@@ -735,4 +735,4 @@ _this._tag = 'TupleType'; | ||
__extends(ReadonlyType, _super); | ||
function ReadonlyType(name, is, validate, serialize, type) { | ||
var _this = _super.call(this, name, is, validate, serialize) || this; | ||
function ReadonlyType(name, is, validate, encode, type) { | ||
var _this = _super.call(this, name, is, validate, encode) || this; | ||
_this.type = type; | ||
@@ -761,4 +761,4 @@ _this._tag = 'ReadonlyType'; | ||
__extends(ReadonlyArrayType, _super); | ||
function ReadonlyArrayType(name, is, validate, serialize, type) { | ||
var _this = _super.call(this, name, is, validate, serialize) || this; | ||
function ReadonlyArrayType(name, is, validate, encode, type) { | ||
var _this = _super.call(this, name, is, validate, encode) || this; | ||
_this.type = type; | ||
@@ -790,4 +790,4 @@ _this._tag = 'ReadonlyArrayType'; | ||
__extends(StrictType, _super); | ||
function StrictType(name, is, validate, serialize, props) { | ||
var _this = _super.call(this, name, is, validate, serialize) || this; | ||
function StrictType(name, is, validate, encode, props) { | ||
var _this = _super.call(this, name, is, validate, encode) || this; | ||
_this.props = props; | ||
@@ -861,4 +861,4 @@ _this._tag = 'StrictType'; | ||
__extends(TaggedUnionType, _super); | ||
function TaggedUnionType(name, is, validate, serialize, types, tag) { | ||
var _this = _super.call(this, name, is, validate, serialize, types) /* istanbul ignore next */ // <= workaround for https://github.com/Microsoft/TypeScript/issues/13455 | ||
function TaggedUnionType(name, is, validate, encode, types, tag) { | ||
var _this = _super.call(this, name, is, validate, encode, types) /* istanbul ignore next */ // <= workaround for https://github.com/Microsoft/TypeScript/issues/13455 | ||
|| this; | ||
@@ -929,4 +929,4 @@ _this.tag = tag; | ||
__extends(ExactType, _super); | ||
function ExactType(name, is, validate, serialize, type) { | ||
var _this = _super.call(this, name, is, validate, serialize) || this; | ||
function ExactType(name, is, validate, encode, type) { | ||
var _this = _super.call(this, name, is, validate, encode) || this; | ||
_this.type = type; | ||
@@ -985,2 +985,1 @@ _this._tag = 'ExactType'; | ||
exports.alias = alias; | ||
//# sourceMappingURL=index.js.map |
@@ -27,2 +27,1 @@ "use strict"; | ||
}; | ||
//# sourceMappingURL=PathReporter.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=Reporter.js.map |
@@ -11,2 +11,1 @@ "use strict"; | ||
}; | ||
//# sourceMappingURL=ThrowReporter.js.map |
{ | ||
"name": "io-ts", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "TypeScript compatible runtime type system for IO validation", | ||
@@ -18,2 +18,3 @@ "files": [ | ||
"build": "npm run clean && tsc", | ||
"prepublish": "npm run build", | ||
"perf": "node perf/index", | ||
@@ -47,3 +48,3 @@ "dtslint": "dtslint dtslint" | ||
"tslint-config-standard": "7.0.0", | ||
"typescript": "^3.0.1" | ||
"typescript": "^3.1.1" | ||
}, | ||
@@ -50,0 +51,0 @@ "tags": [ |
@@ -84,3 +84,3 @@ [![build status](https://img.shields.io/travis/gcanti/io-ts/master.svg?style=flat-square)](https://travis-ci.org/gcanti/io-ts) | ||
The stable version is tested against TypeScript 3.0.1, but should run with TypeScript 2.7.2+ too | ||
The stable version is tested against TypeScript 3.1.1, but should run with TypeScript 2.7.2+ too | ||
@@ -124,3 +124,3 @@ # Error reporters | ||
} | ||
type Context = ReadonlyArray<ContextEntry> | ||
interface Context extends ReadonlyArray<ContextEntry> {} | ||
interface ValidationError { | ||
@@ -130,3 +130,3 @@ readonly value: mixed | ||
} | ||
type Errors = Array<ValidationError> | ||
interface Errors extends Array<ValidationError> {} | ||
``` | ||
@@ -262,3 +262,3 @@ | ||
const Bar: t.RecursiveType<t.Type<IFoo>, IBar> = t.recursion<IBar>('Bar', _ => | ||
const Bar: t.RecursiveType<t.Type<IBar>, IBar> = t.recursion<IBar>('Bar', _ => | ||
t.interface({ | ||
@@ -410,2 +410,40 @@ type: t.literal('Bar'), | ||
# Generic Types | ||
Polymorphic runtime types are represented using functions. | ||
For example, the following typescript: | ||
```ts | ||
interface ResponseBody<T> { | ||
result: T | ||
_links: Links | ||
} | ||
interface Links { | ||
previous: string | ||
next: string | ||
} | ||
``` | ||
Would be: | ||
```ts | ||
import * as t from 'io-ts' | ||
const ResponseBody = <RT extends t.Mixed>(type: RT) => | ||
t.interface({ | ||
result: type, | ||
_links: Links | ||
}) | ||
const Links = t.interface({ | ||
previous: t.string, | ||
next: t.string | ||
}) | ||
``` | ||
And used like: | ||
```ts | ||
const UserModel = t.interface({ name: t.string }) | ||
functionThatRequiresRuntimeType(ResponseBody(t.array(UserModel)), ...params) | ||
``` | ||
# Tips and Tricks | ||
@@ -412,0 +450,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1343
589
83532
12