Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

io-ts

Package Overview
Dependencies
Maintainers
1
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

io-ts - npm Package Compare versions

Comparing version 1.5.2 to 1.5.3

44

CHANGELOG.md

@@ -17,2 +17,46 @@ # Changelog

# 1.5.3
- **Bug Fix**
- missing context info while decoding an intersection, fix #246 (@gcanti)
- **Experimental**
- add intermediary interfaces, closes #165 (@gcanti)
- `NullC`
- `UndefinedC`
- `VoidC`
- `AnyC`
- `UnknownC`
- `NeverC`
- `StringC`
- `NumberC`
- `BooleanC`
- `UnknownArrayC`
- `UnknownRecordC`
- `ObjectC`
- `FunctionC`
- `RefinementC`
- `LiteralC`
- `KeyofC`
- `ArrayC`
- `TypeC`
- `PartialC`
- `RecordC`
- `UnionC`
- `IntersectionC`
- `TupleC`
- `ReadonlyC`
- `ReadonlyArrayC`
- `StrictC`
- `TaggedUnionC`
- `ExactC`
- **Polishs**
- use rest elements in tuple types (`typescript@3.0.1` feature) (@gcanti)
- `union` should handle zero types (@gcanti)
- `intersection` should handle zero / one types (@gcanti)
- **Deprecation**
- deprecate `clean` (@gcanti)
- deprecate `alias` (@gcanti)
- deprecate `PropsOf` type (@gcanti)
- deprecate `Exact` type (@gcanti)
# 1.5.2

@@ -19,0 +63,0 @@

224

lib/index.d.ts

@@ -161,6 +161,11 @@ import { Either } from 'fp-ts/lib/Either';

/**
* @since 1.5.3
*/
export interface NullC extends NullType {
}
/**
* @alias `null`
* @since 1.0.0
*/
export declare const nullType: NullType;
export declare const nullType: NullC;
/**

@@ -173,4 +178,9 @@ * @since 1.0.0

}
declare const undefinedType: UndefinedType;
/**
* @since 1.5.3
*/
export interface UndefinedC extends UndefinedType {
}
declare const undefinedType: UndefinedC;
/**
* @since 1.2.0

@@ -183,6 +193,11 @@ */

/**
* @since 1.5.3
*/
export interface VoidC extends VoidType {
}
/**
* @alias `void`
* @since 1.2.0
*/
export declare const voidType: VoidType;
export declare const voidType: VoidC;
/**

@@ -196,5 +211,10 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface AnyC extends AnyType {
}
/**
* @since 1.0.0
*/
export declare const any: AnyType;
export declare const any: AnyC;
/**

@@ -208,5 +228,10 @@ * @since 1.5.0

/**
* @since 1.5.3
*/
export interface UnknownC extends UnknownType {
}
/**
* @since 1.5.0
*/
export declare const unknown: UnknownType;
export declare const unknown: UnknownC;
/**

@@ -220,5 +245,10 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface NeverC extends NeverType {
}
/**
* @since 1.0.0
*/
export declare const never: NeverType;
export declare const never: NeverC;
/**

@@ -232,5 +262,10 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface StringC extends StringType {
}
/**
* @since 1.0.0
*/
export declare const string: StringType;
export declare const string: StringC;
/**

@@ -244,5 +279,10 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface NumberC extends NumberType {
}
/**
* @since 1.0.0
*/
export declare const number: NumberType;
export declare const number: NumberC;
/**

@@ -256,5 +296,10 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface BooleanC extends BooleanType {
}
/**
* @since 1.0.0
*/
export declare const boolean: BooleanType;
export declare const boolean: BooleanC;
/**

@@ -267,4 +312,9 @@ * @since 1.0.0

}
declare const arrayType: AnyArrayType;
/**
* @since 1.5.3
*/
export interface UnknownArrayC extends AnyArrayType {
}
declare const arrayType: UnknownArrayC;
/**
* @since 1.0.0

@@ -279,5 +329,10 @@ */

/**
* @since 1.5.3
*/
export interface UnknownRecordC extends AnyDictionaryType {
}
/**
* @since 1.0.0
*/
export declare const Dictionary: AnyDictionaryType;
export declare const Dictionary: UnknownRecordC;
/**

@@ -291,5 +346,10 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface ObjectC extends ObjectType {
}
/**
* @since 1.0.0
*/
export declare const object: ObjectType;
export declare const object: ObjectC;
/**

@@ -303,5 +363,10 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface FunctionC extends FunctionType {
}
/**
* @since 1.0.0
*/
export declare const Function: FunctionType;
export declare const Function: FunctionC;
/**

@@ -317,13 +382,19 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface RefinementC<C extends Any> extends RefinementType<C, TypeOf<C>, OutputOf<C>, InputOf<C>> {
}
/**
* @since 1.0.0
*/
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 refinement: <RT extends Any>(type: RT, predicate: Predicate<RT["_A"]>, name?: string) => RefinementC<RT>;
/**
* @since 1.0.0
*/
export declare const Integer: RefinementType<NumberType, number, number, unknown>;
export declare const Integer: RefinementC<NumberC>;
declare type LiteralValue = string | number | boolean;
/**
* @since 1.0.0
*/
export declare class LiteralType<V extends string | number | boolean> extends Type<V> {
export declare class LiteralType<V extends LiteralValue> extends Type<V> {
readonly value: V;

@@ -334,5 +405,10 @@ readonly _tag: 'LiteralType';

/**
* @since 1.5.3
*/
export interface LiteralC<V extends LiteralValue> extends LiteralType<V> {
}
/**
* @since 1.0.0
*/
export declare const literal: <V extends string | number | boolean>(value: V, name?: string) => LiteralType<V>;
export declare const literal: <V extends LiteralValue>(value: V, name?: string) => LiteralC<V>;
/**

@@ -349,2 +425,9 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface KeyofC<D extends {
[key: string]: mixed;
}> extends KeyofType<D> {
}
/**
* @since 1.0.0

@@ -354,3 +437,3 @@ */

[key: string]: unknown;
}>(keys: D, name?: string) => KeyofType<D>;
}>(keys: D, name?: string) => KeyofC<D>;
/**

@@ -378,5 +461,10 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface ArrayC<C extends Mixed> extends ArrayType<C, Array<TypeOf<C>>, Array<OutputOf<C>>, unknown> {
}
/**
* @since 1.0.0
*/
export declare const array: <RT extends Mixed>(type: RT, name?: string) => ArrayType<RT, RT["_A"][], RT["_O"][], unknown>;
export declare const array: <RT extends Mixed>(type: RT, name?: string) => ArrayC<RT>;
/**

@@ -415,6 +503,11 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface TypeC<P extends Props> extends InterfaceType<P, TypeOfProps<P>, OutputOfProps<P>, unknown> {
}
/**
* @alias `interface`
* @since 1.0.0
*/
export declare const type: <P extends Props>(props: P, name?: string) => InterfaceType<P, TypeOfProps<P>, OutputOfProps<P>, unknown>;
export declare const type: <P extends Props>(props: P, name?: string) => TypeC<P>;
/**

@@ -441,5 +534,10 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface PartialC<P extends Props> extends PartialType<P, TypeOfPartialProps<P>, OutputOfPartialProps<P>, unknown> {
}
/**
* @since 1.0.0
*/
export declare const partial: <P extends Props>(props: P, name?: string) => PartialType<P, TypeOfPartialProps<P>, OutputOfPartialProps<P>, unknown>;
export declare const partial: <P extends Props>(props: P, name?: string) => PartialC<P>;
/**

@@ -467,5 +565,10 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface RecordC<D extends Mixed, C extends Mixed> extends DictionaryType<D, C, TypeOfDictionary<D, C>, OutputOfDictionary<D, C>, unknown> {
}
/**
* @since 1.0.0
*/
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>, unknown>;
export declare const dictionary: <D extends Mixed, C extends Mixed>(domain: D, codomain: C, name?: string) => RecordC<D, C>;
/**

@@ -480,5 +583,10 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface UnionC<CS extends [Mixed, Mixed, ...Array<Mixed>]> extends UnionType<CS, TypeOf<CS[number]>, OutputOf<CS[number]>, unknown> {
}
/**
* @since 1.0.0
*/
export declare const union: <RTS extends Mixed[]>(types: RTS, name?: string) => UnionType<RTS, RTS[number]["_A"], RTS[number]["_O"], unknown>;
export declare const union: <RTS extends [Mixed, Mixed, ...Mixed[]]>(types: RTS, name?: string) => UnionC<RTS>;
/**

@@ -501,9 +609,13 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface IntersectionC<CS extends [Mixed, Mixed, ...Array<Mixed>]> extends IntersectionType<CS, CS extends [Mixed, Mixed] ? TypeOf<CS['0']> & TypeOf<CS['1']> : CS extends [Mixed, Mixed, Mixed] ? TypeOf<CS['0']> & TypeOf<CS['1']> & TypeOf<CS['2']> : CS extends [Mixed, Mixed, Mixed, Mixed] ? TypeOf<CS['0']> & TypeOf<CS['1']> & TypeOf<CS['2']> & TypeOf<CS['3']> : CS extends [Mixed, Mixed, Mixed, Mixed, Mixed] ? TypeOf<CS['0']> & TypeOf<CS['1']> & TypeOf<CS['2']> & TypeOf<CS['3']> & TypeOf<CS['4']> : unknown, CS extends [Mixed, Mixed] ? OutputOf<CS['0']> & OutputOf<CS['1']> : CS extends [Mixed, Mixed, Mixed] ? OutputOf<CS['0']> & OutputOf<CS['1']> & OutputOf<CS['2']> : CS extends [Mixed, Mixed, Mixed, Mixed] ? OutputOf<CS['0']> & OutputOf<CS['1']> & OutputOf<CS['2']> & OutputOf<CS['3']> : CS extends [Mixed, Mixed, Mixed, Mixed, Mixed] ? OutputOf<CS['0']> & OutputOf<CS['1']> & OutputOf<CS['2']> & OutputOf<CS['3']> & OutputOf<CS['4']> : unknown, unknown> {
}
/**
* @since 1.0.0
*/
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>;
export declare function intersection<A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed>(types: [A, B, C, D], name?: string): IntersectionType<[A, B, C, D], TypeOf<A> & TypeOf<B> & TypeOf<C> & TypeOf<D>, OutputOf<A> & OutputOf<B> & OutputOf<C> & OutputOf<D>, mixed>;
export declare function intersection<A extends Mixed, B extends Mixed, C extends Mixed>(types: [A, B, C], name?: string): IntersectionType<[A, B, C], TypeOf<A> & TypeOf<B> & TypeOf<C>, OutputOf<A> & OutputOf<B> & OutputOf<C>, mixed>;
export declare function intersection<A extends Mixed, B extends Mixed>(types: [A, B], name?: string): IntersectionType<[A, B], TypeOf<A> & TypeOf<B>, OutputOf<A> & OutputOf<B>, mixed>;
export declare function intersection<A extends Mixed>(types: [A], name?: string): IntersectionType<[A], TypeOf<A>, OutputOf<A>, mixed>;
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): IntersectionC<[A, B, C, D, E]>;
export declare function intersection<A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed>(types: [A, B, C, D], name?: string): IntersectionC<[A, B, C, D]>;
export declare function intersection<A extends Mixed, B extends Mixed, C extends Mixed>(types: [A, B, C], name?: string): IntersectionC<[A, B, C]>;
export declare function intersection<A extends Mixed, B extends Mixed>(types: [A, B], name?: string): IntersectionC<[A, B]>;
/**

@@ -518,9 +630,14 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface TupleC<CS extends [Mixed, ...Array<Mixed>]> extends TupleType<CS, CS extends [Mixed] ? [TypeOf<CS['0']>] : CS extends [Mixed, Mixed] ? [TypeOf<CS['0']>, TypeOf<CS['1']>] : CS extends [Mixed, Mixed, Mixed] ? [TypeOf<CS['0']>, TypeOf<CS['1']>, TypeOf<CS['2']>] : CS extends [Mixed, Mixed, Mixed, Mixed] ? [TypeOf<CS['0']>, TypeOf<CS['1']>, TypeOf<CS['2']>, TypeOf<CS['3']>] : CS extends [Mixed, Mixed, Mixed, Mixed, Mixed] ? [TypeOf<CS['0']>, TypeOf<CS['1']>, TypeOf<CS['2']>, TypeOf<CS['3']>, TypeOf<CS['4']>] : unknown, CS extends [Mixed] ? [OutputOf<CS['0']>] : CS extends [Mixed, Mixed] ? [OutputOf<CS['0']>, OutputOf<CS['1']>] : CS extends [Mixed, Mixed, Mixed] ? [OutputOf<CS['0']>, OutputOf<CS['1']>, OutputOf<CS['2']>] : CS extends [Mixed, Mixed, Mixed, Mixed] ? [OutputOf<CS['0']>, OutputOf<CS['1']>, OutputOf<CS['2']>, OutputOf<CS['3']>] : CS extends [Mixed, Mixed, Mixed, Mixed, Mixed] ? [OutputOf<CS['0']>, OutputOf<CS['1']>, OutputOf<CS['2']>, OutputOf<CS['3']>, OutputOf<CS['4']>] : unknown, unknown> {
}
/**
* @since 1.0.0
*/
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>;
export declare function tuple<A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed>(types: [A, B, C, D], name?: string): TupleType<[A, B, C, D], [TypeOf<A>, TypeOf<B>, TypeOf<C>, TypeOf<D>], [OutputOf<A>, OutputOf<B>, OutputOf<C>, OutputOf<D>], mixed>;
export declare function tuple<A extends Mixed, B extends Mixed, C extends Mixed>(types: [A, B, C], name?: string): TupleType<[A, B, C], [TypeOf<A>, TypeOf<B>, TypeOf<C>], [OutputOf<A>, OutputOf<B>, OutputOf<C>], mixed>;
export declare function tuple<A extends Mixed, B extends Mixed>(types: [A, B], name?: string): TupleType<[A, B], [TypeOf<A>, TypeOf<B>], [OutputOf<A>, OutputOf<B>], mixed>;
export declare function tuple<A extends Mixed>(types: [A], name?: string): TupleType<[A], [TypeOf<A>], [OutputOf<A>], mixed>;
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): TupleC<[A, B, C, D, E]>;
export declare function tuple<A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed>(types: [A, B, C, D], name?: string): TupleC<[A, B, C, D]>;
export declare function tuple<A extends Mixed, B extends Mixed, C extends Mixed>(types: [A, B, C], name?: string): TupleC<[A, B, C]>;
export declare function tuple<A extends Mixed, B extends Mixed>(types: [A, B], name?: string): TupleC<[A, B]>;
export declare function tuple<A extends Mixed>(types: [A], name?: string): TupleC<[A]>;
/**

@@ -535,5 +652,10 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface ReadonlyC<C extends Mixed> extends ReadonlyType<C, Readonly<TypeOf<C>>, Readonly<OutputOf<C>>, unknown> {
}
/**
* @since 1.0.0
*/
export declare const readonly: <RT extends Mixed>(type: RT, name?: string) => ReadonlyType<RT, Readonly<RT["_A"]>, Readonly<RT["_O"]>, unknown>;
export declare const readonly: <RT extends Mixed>(type: RT, name?: string) => ReadonlyC<RT>;
/**

@@ -548,5 +670,10 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface ReadonlyArrayC<C extends Mixed> extends ReadonlyArrayType<C, ReadonlyArray<TypeOf<C>>, ReadonlyArray<OutputOf<C>>, unknown> {
}
/**
* @since 1.0.0
*/
export declare const readonlyArray: <RT extends Mixed>(type: RT, name?: string) => ReadonlyArrayType<RT, ReadonlyArray<RT["_A"]>, ReadonlyArray<RT["_O"]>, unknown>;
export declare const readonlyArray: <RT extends Mixed>(type: RT, name?: string) => ReadonlyArrayC<RT>;
/**

@@ -561,2 +688,7 @@ * @since 1.0.0

/**
* @since 1.5.3
*/
export interface StrictC<P extends Props> extends StrictType<P, TypeOfProps<P>, OutputOfProps<P>, unknown> {
}
/**
* Specifies that only the given properties are allowed

@@ -566,3 +698,3 @@ * @deprecated use `exact` instead

*/
export declare const strict: <P extends Props>(props: P, name?: string) => StrictType<P, TypeOfProps<P>, OutputOfProps<P>, unknown>;
export declare const strict: <P extends Props>(props: P, name?: string) => StrictC<P>;
/**

@@ -609,3 +741,3 @@ * @since 1.3.0

*/
export declare const getTagValue: <Tag extends string>(tag: Tag) => (type: Tagged<Tag, any, any>) => string | number | boolean;
export declare const getTagValue: <Tag extends string>(tag: Tag) => (type: Tagged<Tag, any, any>) => LiteralValue;
/**

@@ -619,5 +751,10 @@ * @since 1.3.0

/**
* @since 1.5.3
*/
export interface TaggedUnionC<Tag extends string, CS extends [Tagged<Tag>, Tagged<Tag>, ...Array<Tagged<Tag>>]> extends TaggedUnionType<Tag, CS, TypeOf<CS[number]>, OutputOf<CS[number]>, unknown> {
}
/**
* @since 1.3.0
*/
export declare const taggedUnion: <Tag extends string, RTS extends Tagged<Tag, any, any>[]>(tag: Tag, types: RTS, name?: string) => TaggedUnionType<Tag, RTS, RTS[number]["_A"], RTS[number]["_O"], unknown>;
export declare const taggedUnion: <Tag extends string, RTS extends [Tagged<Tag, any, any>, Tagged<Tag, any, any>, ...Tagged<Tag, any, any>[]]>(tag: Tag, types: RTS, name?: string) => TaggedUnionC<Tag, RTS>;
/**

@@ -651,8 +788,14 @@ * @since 1.1.0

/**
* @since 1.5.3
*/
export interface ExactC<C extends HasProps> extends ExactType<C, TypeOf<C>, OutputOf<C>, InputOf<C>> {
}
/**
* @since 1.1.0
*/
export declare function exact<RT extends HasProps>(type: RT, name?: string): ExactType<RT, TypeOf<RT>, OutputOf<RT>, InputOf<RT>>;
export declare function exact<RT extends HasProps>(type: RT, name?: string): ExactC<RT>;
/**
* Drops the runtime type "kind"
* @since 1.1.0
* @deprecated
*/

@@ -662,2 +805,3 @@ export declare function clean<A, O = A, I = mixed>(type: Type<A, O, I>): Type<A, O, I>;

* @since 1.0.0
* @deprecated
*/

@@ -669,2 +813,3 @@ export declare type PropsOf<T extends {

* @since 1.1.0
* @deprecated
*/

@@ -683,2 +828,3 @@ export declare type Exact<T, X extends T> = T & {

* @since 1.1.0
* @deprecated
*/

@@ -685,0 +831,0 @@ export declare function alias<A, O, P, I>(type: PartialType<P, A, O, I>): <AA extends Exact<A, AA>, OO extends Exact<O, OO> = O, PP extends Exact<P, PP> = P, II extends I = I>() => PartialType<PP, AA, OO, II>;

9

lib/index.js

@@ -803,3 +803,3 @@ "use strict";

}
return exports.failures(errors);
return errors.length ? exports.failures(errors) : exports.failure(m, c);
}, useIdentity(types, len)

@@ -835,3 +835,3 @@ ? exports.identity

var len = types.length;
return new IntersectionType(name, function (m) { return types.every(function (type) { return type.is(m); }); }, function (m, c) {
return new IntersectionType(name, function (m) { return (len === 0 ? false : types.every(function (type) { return type.is(m); })); }, function (m, c) {
var a = m;

@@ -841,3 +841,3 @@ var errors = [];

var type_5 = types[i];
var validation = type_5.validate(a, c);
var validation = type_5.validate(a, exports.appendContext(c, String(i), type_5));
if (validation.isLeft()) {

@@ -850,3 +850,3 @@ pushAll(errors, validation.value);

}
return errors.length ? exports.failures(errors) : exports.success(a);
return errors.length ? exports.failures(errors) : len === 0 ? exports.failure(m, c) : exports.success(a);
}, useIdentity(types, len)

@@ -1182,2 +1182,3 @@ ? exports.identity

* @since 1.1.0
* @deprecated
*/

@@ -1184,0 +1185,0 @@ function clean(type) {

{
"name": "io-ts",
"version": "1.5.2",
"version": "1.5.3",
"description": "TypeScript compatible runtime type system for IO validation",

@@ -15,3 +15,3 @@ "files": [

"fix-prettier": "prettier --no-semi --single-quote --print-width 120 --parser typescript --write \"{src,test,examples,exercises}/**/*.ts\"",
"test": "npm run prettier && npm run lint && npm run dtslint && npm run jest",
"test": "npm run prettier && npm run lint && npm run dtslint && npm run declaration && npm run jest",
"clean": "rimraf lib/*",

@@ -21,3 +21,5 @@ "build": "npm run clean && tsc",

"perf": "node perf/index",
"dtslint": "dtslint dtslint"
"dtslint": "dtslint dtslint",
"declaration": "tsc -p declaration/tsconfig.json",
"mocha": "TS_NODE_CACHE=false mocha -r ts-node/register test/*.ts"
},

@@ -44,5 +46,7 @@ "repository": {

"jest": "^23.6.0",
"prettier": "1.13.4",
"mocha": "^5.2.0",
"prettier": "^1.15.3",
"rimraf": "2.6.2",
"ts-jest": "^23.10.4",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",

@@ -49,0 +53,0 @@ "tslint-config-standard": "^8.0.1",

@@ -172,6 +172,6 @@ [![build status](https://img.shields.io/travis/gcanti/io-ts/master.svg?style=flat-square)](https://travis-ci.org/gcanti/io-ts)

```ts
interface IPerson extends t.TypeOf<typeof Person> {}
type Person = t.TypeOf<typeof Person>
// same as
interface IPerson {
type Person = {
name: string

@@ -347,8 +347,9 @@ age: number

interface CT extends t.TypeOf<typeof C> {}
type C = t.TypeOf<typeof C>
// same as
type CT = {
type C = {
foo: string
bar?: number
} & {
bar?: number | undefined
}

@@ -367,6 +368,6 @@ ```

interface PartialPerson extends t.TypeOf<typeof PartialPerson> {}
type PartialPerson = t.TypeOf<typeof PartialPerson>
// same as
interface PartialPerson {
type PartialPerson = {
name?: string

@@ -441,3 +442,6 @@ age?: number

```ts
const UserModel = t.interface({ name: t.string })
const UserModel = t.type({
name: t.string
})
functionThatRequiresRuntimeType(ResponseBody(t.array(UserModel)), ...params)

@@ -529,84 +533,1 @@ ```

- quick info stays responsive
# Known issues
VS Code might display weird types for nested types
```ts
const NestedInterface = t.type({
foo: t.string,
bar: t.type({
baz: t.string
})
})
type NestedInterfaceType = t.TypeOf<typeof NestedInterface>
/*
Hover on NestedInterfaceType will display
type NestedInterfaceType = {
foo: string;
bar: t.TypeOfProps<{
baz: t.StringType;
}>;
}
instead of
type NestedInterfaceType = {
foo: string;
bar: {
baz: string
}
}
*/
```
## Solution: the `clean` and `alias` functions
The pattern
```ts
// private runtime type
const _NestedInterface = t.type({
foo: t.string,
bar: t.type({
baz: t.string
})
})
// a type alias using interface
export interface NestedInterface extends t.TypeOf<typeof _NestedInterface> {}
//
// Two possible options for the exported runtime type
//
// a clean NestedInterface which drops the kind...
export const NestedInterface = t.clean<NestedInterface, NestedInterface>(_NestedInterface)
/*
NestedInterface: t.Type<NestedInterface, NestedInterface, t.mixed>
*/
// ... or an alias of _NestedInterface which keeps the kind
export const NestedInterface = t.alias(_NestedInterface)<NestedInterface, NestedInterface>()
/*
t.InterfaceType<{
foo: t.StringType;
bar: t.InterfaceType<{
baz: t.StringType;
}, t.TypeOfProps<{
baz: t.StringType;
}>, t.OutputOfProps<{
baz: t.StringType;
}>, t.mixed>;
}, NestedInterface, NestedInterface, t.mixed>
*/
// you can also alias the props
interface NestedInterfaceProps extends t.PropsOf<typeof _NestedInterface> {}
export const NestedInterface = t.alias(_NestedInterface)<NestedInterface, NestedInterface, NestedInterfaceProps>()
/*
const NestedInterface: t.InterfaceType<NestedInterfaceProps, NestedInterface, NestedInterface, t.mixed>
*/
```
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