Socket
Socket
Sign inDemoInstall

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.0.6 to 1.1.0

5

CHANGELOG.md

@@ -16,2 +16,7 @@ # Changelog

# 1.1.0
* **Experimental**
* add `optional` combinator (@gcanti)
# 1.0.6

@@ -18,0 +23,0 @@

20

lib/index.d.ts

@@ -168,2 +168,8 @@ import { Either } from 'fp-ts/lib/Either';

export declare const array: <RT extends Type<any, any, mixed>>(type: RT, name?: string) => ArrayType<RT, RT["_A"][], RT["_O"][], mixed>;
export declare class OptionalType<RT extends Any, A = any, O = A, I = mixed> extends Type<A, O, I> {
readonly type: RT;
readonly _tag: 'OptionalType';
constructor(name: string, is: OptionalType<RT, A, O, I>['is'], validate: OptionalType<RT, A, O, I>['validate'], serialize: OptionalType<RT, A, O, I>['encode'], type: RT);
}
export declare const optional: <RT extends Type<any, any, mixed>>(type: RT, name?: string) => OptionalType<RT, RT["_A"] | undefined, RT["_O"] | undefined, mixed>;
export declare class InterfaceType<P extends AnyProps, A = any, O = A, I = mixed> extends Type<A, O, I> {

@@ -177,7 +183,17 @@ readonly props: P;

}
export declare type RequiredKeys<P> = {
[K in keyof P]: P[K] extends OptionalType<any> ? never : K;
}[keyof P];
export declare type OptionalKeys<P> = {
[K in keyof P]: P[K] extends OptionalType<any> ? K : never;
}[keyof P];
export declare type TypeOfProps<P extends AnyProps> = {
[K in keyof P]: TypeOf<P[K]>;
[K in RequiredKeys<P>]: TypeOf<P[K]>;
} & {
[K in OptionalKeys<P>]?: TypeOf<P[K]>;
};
export declare type OutputOfProps<P extends AnyProps> = {
[K in keyof P]: OutputOf<P[K]>;
[K in RequiredKeys<P>]: OutputOf<P[K]>;
} & {
[K in OptionalKeys<P>]?: OutputOf<P[K]>;
};

@@ -184,0 +200,0 @@ export interface Props {

@@ -367,2 +367,27 @@ "use strict";

//
// optionals
//
var OptionalType = /** @class */ (function (_super) {
__extends(OptionalType, _super);
function OptionalType(name, is, validate, serialize, type) {
var _this = _super.call(this, name, is, validate, serialize) || this;
_this.type = type;
_this._tag = 'OptionalType';
return _this;
}
return OptionalType;
}(Type));
exports.OptionalType = OptionalType;
exports.optional = function (type, name) {
if (name === void 0) { name = type.name + "?"; }
return new OptionalType(name, function (m) { return undefinedType.is(m) || type.is(m); }, function (i, c) {
if (undefinedType.is(i)) {
return exports.success(i);
}
else {
return type.validate(i, c);
}
}, type.encode === exports.identity ? exports.identity : function (a) { return (undefinedType.is(a) ? a : type.encode(a)); }, type);
};
//
// interfaces

@@ -447,3 +472,6 @@ //

if (encode !== exports.identity) {
s[k] = encode(a[k]);
var v = encode(a[k]);
if (s[k] !== v) {
s[k] = v;
}
}

@@ -450,0 +478,0 @@ }

41

package.json
{
"name": "io-ts",
"version": "1.0.6",
"version": "1.1.0",
"description": "TypeScript compatible runtime type system for IO validation",
"files": ["lib"],
"files": [
"lib"
],
"main": "lib/index.js",

@@ -10,11 +12,8 @@ "typings": "lib/index.d.ts",

"lint": "tslint -p tsconfig.json src/**/*.ts test/**/*.ts",
"typings-checker":
"typings-checker --allow-expect-error --project typings-checker/tsconfig.json typings-checker/index.ts",
"mocha": "TS_NODE_CACHE=false TS_NODE_PROJECT=test/tsconfig.json mocha -r ts-node/register test/*.ts",
"prettier":
"prettier --no-semi --single-quote --print-width 120 --parser typescript --list-different \"{src,test}/**/*.ts\"",
"fix-prettier":
"prettier --no-semi --single-quote --print-width 120 --parser typescript --write \"{src,test,examples,exercises}/**/*.ts\"",
"typings-checker": "typings-checker --allow-expect-error --project typings-checker/tsconfig.json typings-checker/index.ts",
"mocha": "cross-env TS_NODE_CACHE=false TS_NODE_PROJECT=test/tsconfig.json mocha -r ts-node/register test/*.ts",
"prettier": "prettier --no-semi --single-quote --print-width 120 --parser typescript --list-different \"{src,test}/**/*.ts\"",
"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 typings-checker && npm run mocha",
"clean": "rm -rf lib/*",
"clean": "rimraf lib/*",
"build": "npm run clean && tsc",

@@ -41,12 +40,26 @@ "perf": "node perf/index"

"benchmark": "2.1.4",
"cross-env": "^5.1.4",
"mocha": "3.2.0",
"prettier": "^1.11.0",
"prettier": "1.12.1",
"rimraf": "2.6.2",
"ts-node": "3.2.0",
"tslint": "5.9.1",
"tslint-config-standard": "7.0.0",
"typescript": "^2.8.3",
"typescript": "2.8.3",
"typings-checker": "1.1.2"
},
"tags": ["typescript", "validation", "inference", "types", "runtime"],
"keywords": ["typescript", "validation", "inference", "types", "runtime"]
"tags": [
"typescript",
"validation",
"inference",
"types",
"runtime"
],
"keywords": [
"typescript",
"validation",
"inference",
"types",
"runtime"
]
}

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

| partial | `Partial<{ name: string }>` | `$Shape<{ name: string }>` | `t.partial({ name: t.string })` |
| optional | `name?: string` | ✘ | `name: t.optional(t.string)` |
| readonly | `Readonly<T>` | `ReadOnly<T>` | `t.readonly(T)` |

@@ -251,6 +252,27 @@ | readonly array | `ReadonlyArray<number>` | `ReadOnlyArray<number>` | `t.readonlyArray(t.number)` |

Note. You can mix required and optional props using an intersection
**After 1.1.0**
You can mix required and optional props using the `optional` combinator
```ts
const A = t.type({
foo: t.string,
bar: t.optional(t.number)
})
type AT = t.TypeOf<typeof A>
// same as
type AT = {
foo: string
bar?: number
}
```
**Before 1.1.0**
You can mix required and optional props using an intersection
```ts
const A = t.type({
foo: t.string

@@ -424,4 +446,3 @@ })

Due to an upstream [bug](https://github.com/Microsoft/TypeScript/issues/14041), VS Code might display `any` for nested
types
Due to an upstream [bug](https://github.com/Microsoft/TypeScript/issues/14041), VS Code might display weird types for nested types

@@ -428,0 +449,0 @@ ```ts

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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